我有一個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]);
}