我已经检查过如何解决这个问题的例子,但我仍然面对它..
我的代码是
NSEnumerator *enu= [obstacles objectEnumerator];
NSMutableArray *delete = [[NSMutableArray alloc] init];
Object *obj;
while ((obj=[enu nextObject])!=nil)
{
if ([obj isKindOfClass: [BObject class]] && CGPointEqualToPoint(obj.position, point) ) {
[view.objects removeObject: obj];
//[obstacles removeObject: obj];
[delete addObject:obj];
}
}
[obstacles removeObjectsInArray:delete];
[delete release];
错误为*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x6a97ba0> was mutated while being enumerated.'
更新:如果我的obstacles
数组中只有一个对象,则我的代码可以正常工作。它失败了多个对象..