Reputation: 5044
I have two entities pictured below. How do I fetch all of the Node
s for a certain Trip
? And how do I specify the Trip
that I want to fetch?
Upvotes: 0
Views: 44
Reputation: 4897
Assuming you have a managed object context, you'll fetch a group of of Trips using a fetched results controller. You can place a predicate on a fetch, and you'll get back only the record(s) that you've matched. You'll need to review the documentation on NSFetchedResultsController to learn how to obtain the Trip you want from CoreData.
Once you have a Trip, it's easy to get your nodes. Call:
[trip nodesInTrip]
You'll get a set back.
If you're using a table view, it's even easier (this assumes your fetchedResultsController is your table views data source):
-(void)didSelectRowAtIndexPath:indexPath {
Trip *selectedTrip = [[fetchedResultsController fetchedObjects] objectAtIndexPath:indexPath];
NSArray *arrayOfNodes = [selectedTrip nodesInTrip];
Upvotes: 1