views:

96

answers:

2

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 NSFetchedResultsController?

Any ideas on how to best approach this problem?

Thanks!

+1  A: 

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.

TechZen
Thanks. I added a second fetch controller, made sure it doesn't have a delegate, and it worked exactly as intended. Since I don't need to take any action once the second fetch controller has returned its results, I don't need to listen for changes.
futureshocked
A: 

As TechZen stated, the answer is no.

However, you can monitor the saves of the NSManagedObjectContext yourself and react to those saves. If you really do need to watch more than one entity (something that is far more common on the iPad than the iPhone) then add a NSNotification observer on the NSManagedObjectContextDidSaveNotification and look at the -userInfo of the NSNotification that comes back. You can then run predicates on against the results to determine if you need to update your display. That is what the NSFetchedResultsController is doing under the covers.

Marcus S. Zarra