1

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?

1
  • Did you have a look at "Fetching Managed Objects" in the "Core Data Programming Guide" ? Commented Mar 12, 2014 at 18:58

1 Answer 1

1

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];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.