Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import IGListKit
- final class DiffableBox<T>: ListDiffable {
- let value: T
- let identifier: NSObjectProtocol
- let compare: (T, T) -> Bool
- init(value: T, identifier: NSObjectProtocol, compare: @escaping (T, T) -> Bool) {
- self.value = value
- self.identifier = identifier
- self.compare = compare
- }
- func diffIdentifier() -> NSObjectProtocol {
- return identifier
- }
- func isEqual(toDiffableObject object: ListDiffable?) -> Bool {
- guard let other = object as? DiffableBox<T> else {
- return false
- }
- return compare(value, other.value)
- }
- }
- extension DiffableBox where T: Equatable {
- convenience init(value: T, identifier: NSObjectProtocol) {
- self.init(value: value, identifier: identifier, compare: ==)
- }
- }
Add Comment
Please, Sign In to add comment