I have properties firstName and lastName in NSManagedObject class. I need another property uppercaseFirstLetter which is calculated from these two. Property uppercaseFirstLetter can't be transient and it will be using for sectionNamedKeyPath
[[NSFetchedResultsController alloc] initWithFetchRequest: fetchRequest
managedObjectContext: [DatabaseManager context]
sectionNameKeyPath: @"uppercaseFirstLetter"
cacheName: nil];
and for sort descriptor
NSSortDescriptor *sortLastNameDescriptor =
[[NSSortDescriptor alloc] initWithKey: @"uppercaseFirstLetter"
ascending: YES
selector: @selector(localizedStandardCompare:)];
This is code for calculating uppercaseFirstLetter:
NSString *aString = nil;
NSString *lastName = [self valueForKey:@"firstName"];
NSString *firstName = [self valueForKey:@"lastName"];
if (lastName.length) {
aString = [lastName uppercaseString];
} else if (firstName.length) {
aString = [firstName uppercaseString];
} else {
aString = @"#";
}
NSString *stringToReturn = [aString substringToIndex:1];
How i need to create uppercaseFirstLetter and what changes in code should do to attain this result?