Guest User

Untitled

a guest
Aug 18th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. import IGListKit
  2.  
  3. final class DiffableBox<T>: ListDiffable {
  4. let value: T
  5. let identifier: NSObjectProtocol
  6. let compare: (T, T) -> Bool
  7.  
  8. init(value: T, identifier: NSObjectProtocol, compare: @escaping (T, T) -> Bool) {
  9. self.value = value
  10. self.identifier = identifier
  11. self.compare = compare
  12. }
  13.  
  14. func diffIdentifier() -> NSObjectProtocol {
  15. return identifier
  16. }
  17.  
  18. func isEqual(toDiffableObject object: ListDiffable?) -> Bool {
  19. guard let other = object as? DiffableBox<T> else {
  20. return false
  21. }
  22.  
  23. return compare(value, other.value)
  24. }
  25. }
  26.  
  27. extension DiffableBox where T: Equatable {
  28. convenience init(value: T, identifier: NSObjectProtocol) {
  29. self.init(value: value, identifier: identifier, compare: ==)
  30. }
  31. }
Add Comment
Please, Sign In to add comment