我正在使用以下代码,并且在尝试获取对象数量时得到 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];