Search code examples
core-datamodelnsfetchrequest

Retrieve Fetch Request from Managed Object Context


I created a Fetch Request "MyRequest" in the visual editor for my Core Data Model (where you also can visually add Entities as well). Now that the fetch request is created, how can I retrieve the fetch request from the model so I can execute it?

In pseudo code, I'd like to do something like this:

NSFetchRequest *request = [NSFetchRequest fetchRequestWithName:@"MyRequest" inManagedObjectContext:myManagedObjectContext];
NSArray *fetchedObjects = [myManagedObjectContext executeFetchRequest:request error:nil];

Thanks!


Solution

  • NSFetchRequest *fetchRequest = [self.managedObjectModel􏰁 fetchRequestTemplateForName:@"MyRequest"];