onmyway133 / DeepDiff

🦀Amazingly incredible extraordinary lightning fast diffing in Swift
https://onmyway133.com/apps/
Other
2.05k stars 145 forks source link

what about if people have String `ID` not `Int` #44

Closed saroar closed 4 years ago

saroar commented 5 years ago

like this

let old = [
  User(id: "1eqw", name: "Captain America"),
  User(id: "12ed", name: "Captain Marvel"),
  User(id: "3r35s", name: "Thor"),
]

let new = [
  User(id: "1eqw", name: "Captain America"),
  User(id: "sac45", name: "The Binary"),
  User(id: "3r35s", name: "Thor"),
]

let changes = diff(old: old, new: new)
onmyway133 commented 5 years ago

@saroar Hi, you need to conform your model to DiffAware protocol

extension User: DiffAware {
  var diffId: Int {
    return id.hashValue
  }

  static func compareContent(_ a: User, _ b: User) -> Bool {
    return a.name == b.name
  }
}