File tree Expand file tree Collapse file tree 3 files changed +14
-20
lines changed
Example/ViewControllers/Examples Expand file tree Collapse file tree 3 files changed +14
-20
lines changed Original file line number Diff line number Diff line change @@ -15,14 +15,17 @@ public protocol Diffable {
1515 func isEqualToDiffable( _ other: Diffable ? ) -> Bool
1616}
1717
18- extension String : Diffable {
19-
20- public var diffIdentifier : String {
21- return self
18+ public extension Diffable where Self : Hashable {
19+
20+ var diffIdentifier : String {
21+ return String ( hashValue )
2222 }
23+ }
24+
25+ public extension Diffable where Self: Equatable {
2326
24- public func isEqualToDiffable( _ other: Diffable ? ) -> Bool {
25- guard let other = other as? String else { return false }
27+ func isEqualToDiffable( _ other: Diffable ? ) -> Bool {
28+ guard let other = other as? Self else { return false }
2629 return self == other
2730 }
2831}
Original file line number Diff line number Diff line change @@ -70,23 +70,19 @@ class DiffViewController: UITableViewController {
7070
7171// MARK: - Diff Item
7272
73- struct DiffItem {
73+ struct DiffItem : Hashable , Equatable {
7474
7575 let value : Int
7676 let text : String
77- let diffIdentifier : String
7877
7978 init ( _ value: Int , text: String ) {
8079 self . value = value
8180 self . text = text
82- self . diffIdentifier = String ( value)
8381 }
84- }
85-
86- extension DiffItem : Diffable {
8782
88- public func isEqualToDiffable( _ other: Diffable ? ) -> Bool {
89- guard let other = other as? DiffItem else { return false }
90- return self . text == other. text
83+ var hashValue : Int {
84+ return value
9185 }
9286}
87+
88+ extension DiffItem : Diffable { }
Original file line number Diff line number Diff line change @@ -128,11 +128,6 @@ extension Person: Diffable {
128128 public var diffIdentifier : String {
129129 return fullName
130130 }
131-
132- func isEqualToDiffable( _ other: Diffable ? ) -> Bool {
133- guard let other = other as? Person else { return false }
134- return self == other
135- }
136131}
137132
138133extension Person : CustomStringConvertible {
You can’t perform that action at this time.
0 commit comments