Let's say I have a Person entity in my core data model that has a name attribute of type String.
I want to use a sectioned fetch request to list my Person entities sectioned by the first letter of their name.
I wrongly assumed I could just add a property to my NSManagedObject subclass and use it in a sectioned fetch request as follows
extension Person {
var firstLetterOfName: String {
// get the first letter
}
}
@SectionedFetchRequest(
sectionIdentifier: \.firstLetterOfName,
sortDescriptors: [
SortDescriptor(\.name, order: .forward)
])
var people: SectionedFetchResults<String, Person>
However, I end up with an uncaught exception NSUnknownKeyException
How can I define this property in a way that I can use it in the section identifier?