Problem with Core Data - EXC_BAD_ACCESS

Posted by BarrettJ on Stack Overflow See other posts from Stack Overflow or by BarrettJ
Published on 2010-05-04T19:28:14Z Indexed on 2010/05/04 19:38 UTC
Read the original article Hit count: 387

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 seems 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];

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about core-data