-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
Description
ListDiffable isEqual always compares with the same object after the update.
- [ ✅] I have reviewed the
READMEand documentation - [ ✅] I have searched existing issues and this is not a duplicate
General information
IGListKitversion: 3.4.0- iOS version(s): 12.0
- CocoaPods/Carthage version: 1.5.3
- Xcode version: 10.0
- Devices/Simulators affected: All
- Reproducible in the demo project? (Yes/No): Yes
- Related issues: NA
Updating an user object and expecting to reload by adapter.performUpdates by checking isEqual.
I have a ViewController listing all the users from an array of user objects. After selecting one user I want to reload the perticular section.
func didSelectAtIndex(_ index: Int) {
let user = users[index]
user.name = "User " + "\(index) updated"
adapter.performUpdates(animated: true, completion: nil)
}
UserInfo class
class UserInfo: ListDiffable {
var id: Int!
var name: String!
init(id: Int, name: String) {
self.id = id
self.name = name
}
func diffIdentifier() -> NSObjectProtocol {
return id as NSObjectProtocol
}
func isEqual(toDiffableObject object: ListDiffable?) -> Bool {
guard let object = object as? UserInfo else {
return true
}
*both the objects are same, I know I just updated the same object.*
print("self.name = \(self.name)")
print("object.name = \(object.name)")
return self.name == object.name
}
}
Is this an expected behaviour? I know I can reload the SectionController from the same controller using
performBatch like this.
collectionContext?.performBatch(animated: true, updates: { (batchContext) in
object.isSelected = !object.isSelected
batchContext.reload(self)
})
Then what is the use of func isEqual(toDiffableObject object: ListDiffable?) -> Bool ?