IGListDiffable
@protocol IGListDiffable
The IGListDiffable protocol provides the base methods needed to compare the identity and equality of two objects using one of the IGKAlgorithm functions.
-
Returns a key that uniquely identifies the object.
@discussion Two objects may share the same identifier, but are not equal. A common pattern is to import IGListCommon.h and use the NSObject category for automatic conformance. However this means that objects will be identified on their pointer value so finding updates becomes impossible.
Warning
This value should never be mutated.Declaration
Objective-C
- (nonnull id<NSObject>)diffIdentifier;
Swift
func diffIdentifier() -> NSObjectProtocol
Return Value
A key that can be used to uniquely identify the object.
-
Returns a Boolean value that indicates whether the receiver and a given object are equal.
Warning
If you implement a custom isEqual: you must also implement -hash. You can just use the -diffIdentifier value for your hash function:
(NSUInteger)hash { return [[self diffIdentifier] hash]; }
Declaration
Objective-C
- (BOOL)isEqual:(nullable id<IGListDiffable>)object;
Swift
func isEqual(_ object: IGListDiffable?) -> Bool
Parameters
object
The object to be compared to the receiver.
Return Value
YES if the receiver and object are equal, otherwise NO.