Last active
October 2, 2015 09:28
-
-
Save grgcombs/2219225 to your computer and use it in GitHub Desktop.
My Feature Request for NSPropertyDescription (Bug Reporter #11130505)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Enhancement Request for Core Data | |
Apple Radar Issue #11130505 | |
http://openradar.appspot.com/radar?id=3173403 | |
I'd like to see an expansion of the Core Data framework that allows us to add a | |
transient property's underlying code via a block assigned on an | |
NSPropertyDescription, in order to provide an easy means to use transient properties | |
without subclassing the managed object. | |
I create my Core Data model, entities, attributes, and relationships at runtime using | |
a JSON model description. However, in the event that I want to use an | |
NSFetchedResultsController with sections based on (for example) a User object's | |
lastName *initial* letter. Right now, since I don't subclass the objects at design- | |
time, if I want to use sections in the FRC I have to include the actual letter value | |
in a separate "sectionBy" property, then make sure to change it's value whenever | |
someone changes the User's lastName. | |
However, whenever I'm building the NSEntityDescription, it would be far cleaner if I | |
merely needed to create an NSAttributeDescription (call it "sectionBy") and then set | |
it up like follows: | |
*/ | |
+ (NSAttributeDescription *)transientSectionByLastNameInitial { | |
NSAttributeDescription *transient = [[NSAttributeDescription alloc] init]; | |
[transient setName:@"sectionBy"]; | |
[transient setTransient:YES]; | |
[transient setAttributeType:NSUndefinedAttributeType]; | |
[transient setAttributeValueClassName:@"NSString"]; | |
// The Good Stuff | |
[transient setTransientValueWithBlock:(id (^)(void)){ | |
NSString *input = [self valueForKey:@"lastName"]; | |
if (!input || !input.length) | |
return nil; | |
return [input substringToIndex:1]; | |
}]; | |
return transient; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment