Skip to content
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

Merged
merged 5 commits into from
Mar 17, 2013
Merged

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

merged 5 commits into from
Mar 17, 2013

Conversation

echoz
Copy link
Contributor

@echoz echoz commented Oct 2, 2012

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:

  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.

@@ -126,6 +142,18 @@ - (NSArray*)noninheritedRelationships {
return [[[self relationshipsByName] allValues] sortedArrayUsingDescriptors:sortDescriptors];
}
}
/** @TypeInfo NSEntityUserInfoDescription */
Copy link
Contributor Author

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.

@rentzsch
Copy link
Owner

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 2 commits January 17, 2013 00:14
… Misc Merge to use as a conditional.

- Updated templates to not emit structs when the user info dictionary is empty.
@rentzsch
Copy link
Owner

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.

@echoz
Copy link
Contributor Author

echoz commented Mar 17, 2013

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.

@rentzsch
Copy link
Owner

Thanks for the clarification. What are you using entity userinfos for, anyway?

@echoz
Copy link
Contributor Author

echoz commented Mar 17, 2013

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.

@rentzsch
Copy link
Owner

Thanks, good ideas.

rentzsch added a commit that referenced this pull request Mar 17, 2013
[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)
@rentzsch rentzsch merged commit 03bac52 into rentzsch:master Mar 17, 2013
@rentzsch
Copy link
Owner

Thanks! Merged. Sorry for the previous delay, somehow I lost track of this Pull Request.

@echoz
Copy link
Contributor Author

echoz commented Mar 17, 2013

No worries. Just glad to see it merged. :)

@batkuip
Copy link
Contributor

batkuip commented Apr 23, 2013

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.

This was referenced Apr 23, 2013
ddrccw pushed a commit to ddrccw/mogenerator that referenced this pull request Jan 20, 2014
[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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants