mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 14:45:21 +00:00
[Sample] Resolve mutation during enumeration issue
- Mutating a dictionary using -enumerateKeysAndObjectsUsingBlock: can have unintended consequences. - Using a copy of the keys to iterate over the values inside the dictionary instead.
This commit is contained in:
@@ -51,7 +51,9 @@
|
|||||||
|
|
||||||
- (void)willReloadData
|
- (void)willReloadData
|
||||||
{
|
{
|
||||||
[_pendingContexts enumerateKeysAndObjectsUsingBlock:^(NSString *kind, NSMutableArray<ASIndexedNodeContext *> *contexts, BOOL *stop) {
|
NSArray *keys = _pendingContexts.allKeys;
|
||||||
|
for (NSString *kind in keys) {
|
||||||
|
NSMutableArray<ASIndexedNodeContext *> *contexts = _pendingContexts[kind];
|
||||||
// Remove everything that existed before the reload, now that we're ready to insert replacements
|
// Remove everything that existed before the reload, now that we're ready to insert replacements
|
||||||
NSArray *indexPaths = [self indexPathsForEditingNodesOfKind:kind];
|
NSArray *indexPaths = [self indexPathsForEditingNodesOfKind:kind];
|
||||||
[self deleteNodesOfKind:kind atIndexPaths:indexPaths completion:nil];
|
[self deleteNodesOfKind:kind atIndexPaths:indexPaths completion:nil];
|
||||||
@@ -72,7 +74,7 @@
|
|||||||
[self insertNodes:nodes ofKind:kind atIndexPaths:indexPaths completion:nil];
|
[self insertNodes:nodes ofKind:kind atIndexPaths:indexPaths completion:nil];
|
||||||
}];
|
}];
|
||||||
[_pendingContexts removeObjectForKey:kind];
|
[_pendingContexts removeObjectForKey:kind];
|
||||||
}];
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)prepareForInsertSections:(NSIndexSet *)sections
|
- (void)prepareForInsertSections:(NSIndexSet *)sections
|
||||||
|
|||||||
Reference in New Issue
Block a user