Core data: can NSFetchedResultsController fetch two different entities?

futureshocked picture futureshocked · Jun 30, 2010 · Viewed 10.6k times · Source

I am working on an iPhone app, and in a particular view I need to load two different entities: One that will populate a UITableView, and another that will populate a UITextView.

Is it possible to fetch both properties using a single NSFetchedResultsController?

Or do I need to use two different NSFetchedResultsControllers?

Any ideas on how to best approach this problem?

Answer

TechZen picture TechZen · Jun 30, 2010

Each fetch request has only one entity and each fetched results controller has only one fetch. Therefore, you need separate controllers for each entity.

If you think about it, how would you make a predicate to fetch two logically separate entities?

You probably don't need two fetches at all. In most cases, you can fetch the entities that populate the table and then use a relationship for the entity of the selected row to populate something like a text view.