My Core Data model has two entities: Author and Book with a To-Many relationship (one author->many books). In the main view I display a list of
I know this is a very old question, but after spending so much time researching, testing and trying to resolve the same situation for myself, I want to share my findings. I am fairly certain that this is an Apple bug and I have filed Feedback FB7960282 for the issue of the name property of the NSFetchedResultsSectionInfo not always having the correct value.
My Objc is a little rusty, so I will give my the workaround in Swift.
// This is a workaround for an apparent bug where the name property of an NSFetchedResultsSectionInfo
// element sometimes provides an incorrect name for the section.
private func name(for section: NSFetchedResultsSectionInfo) -> String {
// The objects property of the NSFetchedResultsSectionInfo should always have at least one element
let object = section.objects?.first as! NSObject
// The name of the section should be the value of the Key Path of all objects in the array
let name = object.value(forKeyPath: self.frc.sectionNameKeyPath!) as? String ?? ""
return name
}
The above function assumes that self.frc is your fetched results controller.
BTW, since your query is returning books, if you want to react to changes to authors, you should observe for NSManagedObjectContextDidSave notifications.