【发布时间】:2011-04-01 23:53:00
【问题描述】:
我有一个 for 循环,由于某种原因,它不允许我删除数组中的所有对象,只有几个。
我做错了什么?
- (void)deleteAllObjects {
AppDelegate *appDel = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSLog(@"Before: %d", [histArray count]);
for (int i = 0; i < [histArray count]; i++) {
History *h = (History *)[histArray objectAtIndex:i];
[[appDel managedObjectContext] deleteObject:h];
[histArray removeObject:h];
[appDel saveContext];
NSLog(@"During: %d", [histArray count]);
[self fetchUpdates];
}
NSLog(@"After: %d", [histArray count]);
}
【问题讨论】:
标签: iphone objective-c xcode core-data loops