I’m getting a EXC_BAD_ACCESS error when this code gets called NSLog(@"Count: %@", [fetchedObjects count]);. It seems like it is because the objects are not yet fetched or something like that because fetchedObjects is not nil. I noticed that if I change count for lastObject it works and the following gets printed in the console
<Albums: 0x4dc7120> (entity: Albums; id: 0x4d9ad60 <x-coredata://xxxxxxxxxxxxxxxx/Albums/p1> ; data: <fault>)
Code
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Albums" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
NSError *error = nil;
NSArray *fetchedObjects = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
if (error != nil) {
NSLog(@"Error: %@", error);
}
if (fetchedObjects != nil) {
NSLog(@"objects is not nil");
}
NSLog(@"Count: %@", [fetchedObjects lastObject]);
for (Albums *info in fetchedObjects) {
NSLog(@"Album: %@", info);
NSLog(@"Name: %@", info.name);
}
[fetchRequest release];
If any of you guys have any pointers, that would be great.
Thank you!
Update
I realized the format specifier should be %d or %i, my mistake. However I get the same error when I call the count function in the numbersOfRowsInSection method.
Use
%dor%ias the format specifiers to print int values.