谁能帮我理解我在这里做错了什么会导致这个堆栈跟踪:
1 libobjc.A.dylib 0x3a8a897a objc_exception_throw + 26
2 CoreFoundation 0x32b7fd80 __NSFastEnumerationMutationHandler + 124
3 CoreFoundation 0x32adbcee -[NSArray containsObject:] + 134
代码如下:
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
通过以下方式传递给此类:
@property (nonatomic, strong) NSMutableArray *tempItemsArray;
我的应用中的其他地方确实有这段代码:
if (appDelegate.loading)
appDelegate.tempItemsArray = itemsArray;
else
appDelegate.itemsArray = itemsArray;
[tblView reloadData];
谢谢!
最佳答案
目前 tempItemsArray 和 itemsArray 是对同一个数组对象的引用。从技术上讲,您是在同时循环和修改同一个数组。
尝试为 tempItemsArray 或 itemsArray 复制数组:
if (appDelegate.loading)
appDelegate.tempItemsArray = [NSMutableArray arrayWithArray:itemsArray];
else
appDelegate.itemsArray = itemsArray;
[tblView reloadData];
关于ios - 为什么我会得到一个带有这个 NSMutableArray 代码的 NSFastEnumerationMutationHandler?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16974628/