-
Notifications
You must be signed in to change notification settings - Fork 395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generation of Entity User Info Key/Value pairs as const Structs #131
Conversation
@@ -126,6 +142,18 @@ - (NSArray*)noninheritedRelationships { | |||
return [[[self relationshipsByName] allValues] sortedArrayUsingDescriptors:sortDescriptors]; | |||
} | |||
} | |||
/** @TypeInfo NSEntityUserInfoDescription */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not too sure what to name this but to keep with convention, this was decided.
Interesting. I'd accept this Pull Request except it sounds like empty structs trigger warnings in pedantic mode (see #133). Could you enhance the template to conditionally emit the userinfo struct only if the dictionary isn't empty? |
… Misc Merge to use as a conditional. - Updated templates to not emit structs when the user info dictionary is empty.
So I added a UserInfo entry to my ParentMO, and it generated this code:
Is this correct? I expected a one-to-one key name mapping, not the value. For example, here's are the generated attributes:
Notice how the struct names are pretty much just symbols for the string constant. |
Hi rentzsch, that is the correct behavior. The assumption here being that the values in the model's user info dictionary is pretty much constant (can't change it at runtime anyways). This allows one to access those key value pairs without needing to spin up the managed model or a managed object connected to a context and in turn a model in order to access those key value pairs. |
Thanks for the clarification. What are you using entity userinfos for, anyway? |
In my use case it was for contextual configuration information about entities that other systems will read (ie. parsing json dictionaries to managed objects based on a configured primary key that is set to a property of that entity). Another use case is to set the REST based URL that an entity is related to which once again a networking stack can use to automatically persist data to or from the REST resource. |
Thanks, good ideas. |
[NEW] Entity-level User Info Key/Value pairs are generated as const Structs. Use it to aid parsing JSON dictionaries or perhaps specify an entity's REST-based URL. (Jeremy Foo)
Thanks! Merged. Sorry for the previous delay, somehow I lost track of this Pull Request. |
No worries. Just glad to see it merged. :) |
Can you fix this to properly handle keys like "com.apple.syncservices.Syncable"? CoreData added this one to all my entities automatically unfortunately this causes a complication failure since the dots are not parse out. |
[NEW] Entity-level User Info Key/Value pairs are generated as const Structs. Use it to aid parsing JSON dictionaries or perhaps specify an entity's REST-based URL. (Jeremy Foo)
Allows generation of the Key Value pairs for each entity as const structs within the machine.h and machine.m files allow easy access of such constants in code.
Changed: