Generation of Entity User Info Key/Value pairs as const Structs #131

merged 5 commits into from Mar 17, 2013

3 participants


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.

1. Added methods to generate the user info key value pairs as a method that Misc Merge can understand.
2. Modified machine.h and machine.m templates to allow generation of user info key/value pair const structs.

@echoz echoz commented on the diff Oct 2, 2012
@@ -126,6 +142,18 @@ - (NSArray*)noninheritedRelationships {
return [[[self relationshipsByName] allValues] sortedArrayUsingDescriptors:sortDescriptors];
+/** @TypeInfo NSEntityUserInfoDescription */
echoz added a note Oct 2, 2012

Not too sure what to name this but to keep with convention, this was decided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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?

echoz added some commits Jan 17, 2013
@echoz echoz - Detects if the user info dictionary is empty and provides a way for…
… Misc Merge to use as a conditional.

- Updated templates to not emit structs when the user info dictionary is empty.
@echoz echoz Forgotten to include in the @interface section 4ca4405

So I added a UserInfo entry to my ParentMO, and it generated this code:

const struct ParentMOUserInfo ParentMOUserInfo = {
    .MyUserInfoKey = @"MyUserInfoValue",

Is this correct? I expected a one-to-one key name mapping, not the value. For example, here's are the generated attributes:

const struct ParentMOAttributes ParentMOAttributes = {
    .myBinaryData = @"myBinaryData",
    .myBoolean = @"myBoolean",
    .myDate = @"myDate",
    .myDecimal = @"myDecimal",
    .myDouble = @"myDouble",
    .myFloat = @"myFloat",
    .myInt16 = @"myInt16",
    .myInt16Transient = @"myInt16Transient",
    .myInt32 = @"myInt32",
    .myInt64 = @"myInt64",
    .myString = @"myString",
    .myTransformableSansClassName = @"myTransformableSansClassName",
    .myTransformableWithClassName = @"myTransformableWithClassName",
    .myTransformableWithProtocol = @"myTransformableWithProtocol",
    .parentName = @"parentName",

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.

@rentzsch rentzsch merged commit 03bac52 into rentzsch:master Mar 17, 2013

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 ""? CoreData added this one to all my entities automatically unfortunately this causes a complication failure since the dots are not parse out.

This was referenced Apr 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment