[英]Why am I getting a NSFastEnumerationMutationHandler with this NSMutableArray code?
Can someone help me understand what I am doing wrong here that would caused this stack trace: 有人可以帮助我理解我在这里做错了会导致这个堆栈跟踪:
1 libobjc.A.dylib 0x3a8a897a objc_exception_throw + 26
2 CoreFoundation 0x32b7fd80 __NSFastEnumerationMutationHandler + 124
3 CoreFoundation 0x32adbcee -[NSArray containsObject:] + 134
Here is the code: 这是代码:
NSMutableArray *leftoverArray = [[NSMutableArray alloc] initWithArray:itemsArray];
for (NSDictionary *tempItem in tempItemsArray)
{
if (![itemsArray containsObject:tempItem])
{
[itemsArray addObject:tempItem];
}
else
{
[leftoverArray removeObject:tempItem];
}
}
for (NSDictionary *item in leftoverArray)
{
[itemsArray removeObject:item];
}
[mainController.tblView reloadData];
tempItemsArray
is passed in to this class via: tempItemsArray
通过tempItemsArray
方式传递给此类:
@property (nonatomic, strong) NSMutableArray *tempItemsArray;
I do have this code elsewhere in my app: 我在我的应用程序的其他地方有这个代码:
if (appDelegate.loading)
appDelegate.tempItemsArray = itemsArray;
else
appDelegate.itemsArray = itemsArray;
[tblView reloadData];
Thanks! 谢谢!
Currently tempItemsArray and itemsArray are a reference to the same array object. 目前tempItemsArray和itemsArray是对同一个数组对象的引用。 You are technically looping and modifying the same array at the same time. 从技术上讲,您可以同时循环和修改同一个阵列。
Try to make a copy of the array for the tempItemsArray or itemsArray: 尝试为tempItemsArray或itemsArray制作数组的副本:
if (appDelegate.loading)
appDelegate.tempItemsArray = [NSMutableArray arrayWithArray:itemsArray];
else
appDelegate.itemsArray = itemsArray;
[tblView reloadData];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.