IGListKit/Source/Internal/IGListBatchUpdates.m
Ryan Nystrom 073fc073e0 Prevent duplicate item deletes and drop reload collisions
Summary:
a415ef5552 exposed a bug in `UICollectionView` where its state gets corrupted when deleting the same index path more than once in a single batch update block. This resulted crashes like

```
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x4)
Closes https://github.com/Instagram/IGListKit/pull/657

Reviewed By: jessesquires

Differential Revision: D4913790

Pulled By: rnystrom

fbshipit-source-id: 8f6fcdd2e2438da309fc64ca0ac111b9a0980149
2017-04-19 17:17:41 -07:00

36 lines
1 KiB
Objective-C

/**
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import "IGListBatchUpdates.h"
@implementation IGListBatchUpdates
- (instancetype)init {
if (self = [super init]) {
_sectionReloads = [NSMutableIndexSet new];
_itemInserts = [NSMutableArray new];
_itemMoves = [NSMutableArray new];
_itemDeletes = [NSMutableArray new];
_itemReloads = [NSMutableArray new];
_itemUpdateBlocks = [NSMutableArray new];
_itemCompletionBlocks = [NSMutableArray new];
}
return self;
}
- (BOOL)hasChanges {
return [self.itemUpdateBlocks count] > 0
|| [self.sectionReloads count] > 0
|| [self.itemInserts count] > 0
|| [self.itemMoves count] > 0
|| [self.itemReloads count] > 0
|| [self.itemDeletes count] > 0;
}
@end