0

I am using Core Data on iOS and am having problems with NSFetchRequest.

If I create an NSFetchRequest like so:

NSFetchRequest* request = [ NSFetchRequest fetchRequestWithEntityName:@"Recipe"];

and then create instances of my Recipe entity, they appear in the results of the fetch request as expected. But once I save the database, and try to reload them then my fetch request returns no results.

The database saves successfully, with no errors, and using SQLite database browser I can see that all my entities have been saved in the underlying SQLite database. But they won't load...

is there an easy way to diagnose what is happening under the hood in a NSFetchRequest so I can find out why it won't load my entities?

// load recipes unsorted
NSFetchRequest* request = [ NSFetchRequest fetchRequestWithEntityName:@"Recipe"];
request.sortDescriptors = [[NSArray alloc] init];

NSFetchedResultsController* frc = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:self.recipeDatabase.managedObjectContext sectionNameKeyPath:nil cacheName:nil];

// fetch results empty
NSError* error = nil;
[frc performFetch:&error];    
Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
deltanine
  • 1,166
  • 1
  • 13
  • 25

1 Answers1

0

Sorry.... I found my problem. I was not opening the UIManagedDocument when the state was UIDocumentStateClosed. Strange that everything else seems to work when operating on the documents managedObjectContext, even though the document is closed.

Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
deltanine
  • 1,166
  • 1
  • 13
  • 25