Search code examples
iphonensfetchedresultscontrollersectionheader

How to fetch section name when using NSFetchedResultsController and sectionNameKeyPath is a relationship?


In the following code:

NSFetchedResultsController *frc =
[[NSFetchedResultsController alloc]
 initWithFetchRequest:fetchRequest
 managedObjectContext:myManagedObjectContext
 sectionNameKeyPath:@"store"
 cacheName:@"SomeCache"
 ];

The @"store" value for sectionNameKeyPath actually points to a relationship to a Store entity which has a name attribute that I really need as my section header title.

But the way my code is setup it cannot be accomplished as I instead get section titles like: 0x5b504f0 0x5b51190 Which are code data addresses for the Store object being fetched as far as I can tell.

How can I use NSFetchedResultsController so that I may tell it that I want it to fetch the name attribute of whatever it fetches from sectionNameKeyPath:@"store" ? Or is there some other workaround?


Solution

  • Try sectionNameKeyPath:@"store.name"