How to get section name when using NSFetchedResultsController and sectionNameKeyPath - this 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 refers to a Store object that has a name attribute that I really need as the title of the section header.

But the way my code is configured cannot be done, because instead I get the section headers: 0x5b504f0 0x5b51190 What code address addresses for the Store object are retrieved, as far as I can tell.

How can I use NSFetchedResultsController so that I can tell him that I want it to retrieve the name attribute of what it retrieves from the NameKeyPath: @ "store" section? Or is there another workaround?

+5
2

sectionNameKeyPath:@"store.name"

+5

, , Swift.

, , NSFetchedResultsController, , Apple.

URI , , URI, URI

override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    let sectionInfo = fetchedResultsController?.sections![section]
    let sectionName = sectionInfo?.name

    //This part depends on the internal implementation of sectionInfo.name
    let initialRange = sectionName?.rangeOfString("<")
    let finalRange = sectionName?.rangeOfString(">")

    let uri = sectionName?.substringWithRange((initialRange?.endIndex)!..<(finalRange?.startIndex)!)
    let url = NSURL(string: uri!)

    let store = fetchedResultsController?.managedObjectContext.persistentStoreCoordinator

    let objectID = store?.managedObjectIDForURIRepresentation(url!)
    let coreObject = fetchedResultsController?.managedObjectContext.objectWithID(objectID!)
    //return the correct property from the object as the title
    let title = ...
    return title
}

, ( guard let), .

+1

All Articles