开发者

Problem with Core Data - EXC_BAD_ACCESS

开发者 https://www.devze.com 2022-12-28 22:49 出处:网络
I\'m using the following code and I\'m getting an EXC_BAD_ACCESS when trying to get the count of objects - anyone have any idea why?Oddly enough, the error only happens if the count should be one or g

I'm using the following code and I'm getting an EXC_BAD_ACCESS when trying to get the count of objects - anyone have any idea why? Oddly enough, the error only happens if the count should be one or greater, if there are no objects it s开发者_开发百科eems to work fine (it outputs 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];


Use %d instead of %@ in format strings for integers:

NSLog(@"%d", count);

Here's a list of String Format Specifiers.

0

精彩评论

暂无评论...
验证码 换一张
取 消