我正在使用以下代码,并且在尝试获取对象计数时我得到了一个EXC_BAD_ACCESS - 任何人都知道为什么?奇怪的是,只有当计数应该是1或更大时才会发生错误,如果没有对象它似乎工作正常(它输出null)。
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"TVShow" inManagedObjectContext:[self managedObjectContext]];
[fetchRequest setEntity:entity];
[fetchRequest includesPendingChanges];
//NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ID == %@", showId];
//[fetchRequest setPredicate:predicate];
NSError *error;
NSLog(@"Generating Count");
NSUInteger count = [[self managedObjectContext] countForFetchRequest:fetchRequest error:&error];
if(count == NSNotFound) {
NSLog(@"error");
}
else {
NSLog(@"%@", count); // EXC_BAD_ACCESS here
}
[fetchRequest release];