Reputation: 81
I have a core data entity with many attributes and I need to be able to access them based on the value of one attribute. For example I have an attribute "Trip" and I need to be able to access the values of the others based on the value of "Trip". So I need to fetch all the values for any object that has a "Trip" value of 1. How do I go about specifying this in the code?
Upvotes: 1
Views: 937
Reputation: 69047
Pretty basic question. You can use a NSFetchRequest
:
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"trip == %@", yourTrip];
[request setEntity:[NSEntityDescription entityForName:@"Trips" inManagedObjectContext:moc]];
[request setPredicate:predicate];
NSError *error = nil;
NSArray *results = [moc executeFetchRequest:request error:&error];
Upvotes: 1