Fetch request error: no entity? Probably easy, but help!

Posted by cksubs on Stack Overflow See other posts from Stack Overflow or by cksubs
Published on 2010-06-03T00:51:39Z Indexed on 2010/06/03 0:54 UTC
Read the original article Hit count: 477

Hi, I'm going through the Stanford iPhone course. I'm on the second Paparazzi assignment.

I'm getting this error:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'executeFetchRequest:error: A fetch request must have an entity.'

I've copied a lot of the code from this walkthrough site. Running his source code works perfectly, and at this point my code is pretty much exactly the same as his. But it throws that error.

See below for the relavent bits:

// Create FetchRequest
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:context]; 
[request setEntity:entity];

// Set the sort descriptor
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"personName" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
[sortDescriptors release];
[sortDescriptor release];

// set up NSFetchedResultsController to hold the fetch
NSFetchedResultsController *frc = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:context sectionNameKeyPath:nil cacheName:@"personCache"];
// execute the fetch
NSError *error;
NSLog(@"Prints Here");

[frc performFetch:&error];
NSLog(@"Doesn't Print Here");

I'm clearly setting the entity with [request setEntity:entity]. So the error has me stumped. Is there something I'm missing? Maybe in another file? I don't know. I'm still so confused with Objective-C....

Thanks.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c