diff --git a/Source/IGListAdapter.m b/Source/IGListAdapter.m index c58a8e81..7b9b0a08 100644 --- a/Source/IGListAdapter.m +++ b/Source/IGListAdapter.m @@ -259,13 +259,13 @@ return; } - NSArray *fromObjects = [self.sectionMap.objects copy]; - NSArray *newItems = [[dataSource objectsForListAdapter:self] copy]; + NSArray *fromObjects = self.sectionMap.objects; + NSArray *newObjects = [dataSource objectsForListAdapter:self]; __weak __typeof__(self) weakSelf = self; [self.updater performUpdateWithCollectionView:collectionView fromObjects:fromObjects - toObjects:newItems + toObjects:newObjects animated:animated objectTransitionBlock:^(NSArray *toObjects) { // temporarily capture the item map that we are transitioning from in case diff --git a/Source/Internal/IGListSectionMap.m b/Source/Internal/IGListSectionMap.m index 66a9fded..8a5ecb42 100644 --- a/Source/Internal/IGListSectionMap.m +++ b/Source/Internal/IGListSectionMap.m @@ -14,10 +14,10 @@ @interface IGListSectionMap () // both of these maps allow fast lookups of objects, list objects, and indexes -@property (nonatomic, strong, readonly) NSMapTable *> *objectToSectionControllerMap; -@property (nonatomic, strong, readonly) NSMapTable *, NSNumber *> *sectionControllerToSectionMap; +@property (nonatomic, strong, readonly, nonnull) NSMapTable *> *objectToSectionControllerMap; +@property (nonatomic, strong, readonly, nonnull) NSMapTable *, NSNumber *> *sectionControllerToSectionMap; -@property (nonatomic, strong, readwrite) NSArray *objects; +@property (nonatomic, strong, nonnull) NSMutableArray *mObjects; @end @@ -33,7 +33,7 @@ _sectionControllerToSectionMap = [[NSMapTable alloc] initWithKeyOptions:NSMapTableStrongMemory | NSMapTableObjectPointerPersonality valueOptions:NSMapTableStrongMemory capacity:0]; - _objects = [NSArray new]; + _mObjects = [NSMutableArray new]; } return self; } @@ -41,6 +41,10 @@ #pragma mark - Public API +- (NSArray *)objects { + return [self.mObjects copy]; +} + - (NSInteger)sectionForSectionController:(IGListSectionController *)sectionController { IGParameterAssert(sectionController != nil); @@ -55,7 +59,7 @@ - (void)updateWithObjects:(NSArray *)objects sectionControllers:(NSArray *)sectionControllers { IGParameterAssert(objects.count == sectionControllers.count); - self.objects = [objects copy]; + self.mObjects = [objects mutableCopy]; [self reset]; @@ -74,8 +78,8 @@ return [self.objectToSectionControllerMap objectForKey:object]; } -- (id)objectForSection:(NSInteger)section { - NSArray *objects = self.objects; +- (nullable id)objectForSection:(NSInteger)section { + NSArray *objects = self.mObjects; if (section < objects.count) { return objects[section]; } else { @@ -105,10 +109,7 @@ id sectionController = [self sectionControllerForObject:object]; [self.sectionControllerToSectionMap setObject:@(section) forKey:sectionController]; [self.objectToSectionControllerMap setObject:sectionController forKey:object]; - - NSMutableArray *mobjects = [self.objects mutableCopy]; - mobjects[section] = object; - self.objects = [mobjects copy]; + self.mObjects[section] = object; } - (void)enumerateUsingBlock:(void (^)(id object, IGListSectionController *sectionController, NSInteger section, BOOL *stop))block { @@ -131,8 +132,10 @@ - (id)copyWithZone:(NSZone *)zone { IGListSectionMap *copy = [[IGListSectionMap allocWithZone:zone] initWithMapTable:self.objectToSectionControllerMap]; - copy->_sectionControllerToSectionMap = [self.sectionControllerToSectionMap copy]; - copy->_objects = [self.objects copy]; + if (copy != nil) { + copy->_sectionControllerToSectionMap = [self.sectionControllerToSectionMap copy]; + copy->_mObjects = [self.mObjects mutableCopy]; + } return copy; }