I’m using the following code to fetch data out of my Core Data graph:
- (void)setupFetchedResultsController
{
// 1 - Decide what Entity you want
NSString *entityName = @"Snag"; // Put your entity name here
NSLog(@"Setting up a Fetched Results Controller for the Entity named %@", entityName);
// 2 - Request that Entity
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:entityName];
// 3 - Filter it if you want
request.predicate = [NSPredicate predicateWithFormat:@"project.id = %@", projectPassedToController.id];
// 4 - Sort it if you want
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"dateTaken"
ascending:YES
selector:@selector(localizedCaseInsensitiveCompare:)]];
// 5 - Fetch it
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:self.managedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
However, I only want to return projects that have the same unique identifier as the one that is being passed to this View Controller (using the ProjectPassedToController variable)
I don’t want to filter by the project.name, as this field is editable by the user. I need to filter by the project’s unique identifier but i’m not sure how to do this.
Solved this by filtering on the relationship between the project and person.