My question is similar this one here:
ResultsController to another ResultsController
A typical app structure on ios is to drill down into data via table views, and plenty of app models are hierarchical. For example, a Film Festival could have many Films, which could have many Screenings, which could have many Attendees. If we use Core Data to represent this model, then we can use an NSFetchedResultsController to populate Films into a UITableView. Using the NSFetchedResultsController helps greatly with performance and memory efficiency, and provides built-in support for observing changes to the underlying data. I would like to take advantage of this in my project as much as I can.
So if we have a table of Films backed by this sweet NSFetchedResultsController, and the user selects a Film to see a list of its Screenings, we can pass that Film (a subclass of NSManagedObject) to a new UITableViewController and populate that table with the film’s screenings.
The core of my question is not “How do I do this?” Instead, it’s asking if the benefits of NSFetchedResultsController travel along with the NSManagedObject. I could build a new results controller using the event in the predicate, but I don’t need to. If I pass the Film object into a variable called film, and my to-many relationship is identified as screenings, then I believe I can get the set of screenings related to that film like this:
NSSet *filmScreenings = [film screenings];
If I turn that set into an array, and use that as the data backing my new table view of screenings, am I losing the benefits of the NSFetchedResultsController? My gut tells me yes, especially the support for monitoring changes – but an FAQ in Apple’s docs made me second guess and ask the community at large. Check out the question in this FAQ called “I have a to-many relationship from Entity A to Entity B…”
Should I use that accessor method then, or should I build a new NSFetchedResultsController?
You will lose the benefits of
NSFetchedResultsControllerby doing this (e.g. batch fetching and change monitoring), as you’re going to replace it with a simpleNSArray. You’re best bet is to pass yourFilmto the details controller, and construct anNSFetchedResultsControllerusing thisFilmin the predicate for theNSFetchRequest.