Assert nil diff identifier, remove if nil

Summary:
Do not allow `nil` diff identifiers to get through. Pluck the objects if this happens and assert.

- Fix the bug if it happens
- Assert to tell the developer what is wrong

Differential Revision: D4753827

fbshipit-source-id: 3a92543c648ed7157ec30af7cb1c91a6e6238e33
This commit is contained in:
Ryan Nystrom 2017-03-22 09:35:27 -07:00 committed by Facebook Github Bot
parent 353d90f397
commit af984ca81d

View file

@ -97,7 +97,8 @@ static NSArray *objectsWithDuplicateIdentifiersRemoved(NSArray<id<IGListDiffable
NSMutableArray *uniqueObjects = [NSMutableArray new];
for (id<IGListDiffable> object in objects) {
id diffIdentifier = [object diffIdentifier];
if (![identifiers containsObject:diffIdentifier]) {
if (diffIdentifier != nil
&& ![identifiers containsObject:diffIdentifier]) {
[identifiers addObject:diffIdentifier];
[uniqueObjects addObject:object];
} else {
@ -385,6 +386,8 @@ static NSUInteger IGListIdentifierHash(const void *item, NSUInteger (*size)(cons
for (id obj in toObjects) {
IGAssert([obj conformsToProtocol:@protocol(IGListDiffable)],
@"In order to use IGListAdapterUpdater, object %@ must conform to IGListDiffable", obj);
IGAssert([obj diffIdentifier] != nil,
@"Cannot have a nil diffIdentifier for object %@", obj);
}
#endif