Multiple NSFetchedResultControllers for different objects?

I am checking the default Xcode template for the iPhone Core Data project. In the method that returns the selected result controller, I see the following:

- (NSFetchedResultsController *)fetchedResultsController { ... NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:managedObjectContext]; [fetchRequest setEntity:entity]; ... return fetchedResultsController; } 

It seems that the name of a specific entity is given. What if I have multiple objects? Will I have two instances of NSFetchedResultsController and there are two methods that return the correct controller depending on which object I use?

thanks

+6
objective-c iphone cocoa-touch core-data nsfetchedresultscontroller
source share
1 answer

It depends.

For example, if you have a Person object and an Employee that inherits from Person, then you can use one NSFetchedResultsController for a Person object that will retrieve both people and employees. However, if you have something like the essence Fruit and Person (and Person is not inherited from Fruit and vice versa), then you can hardly use 1 NSFetchedResultsController to get Fruit and Person.

Whether you need 1 or more NSFetchedResultsController depends on the inheritance hierarchy of your object.

+6
source share

All Articles