Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #131 from echoz/master

[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)
  • Loading branch information...
commit 03bac52a85b5e610ac58e119ccfb80009c2039df 2 parents 0d14b2f + 4ca4405
@rentzsch authored
View
33 mogenerator.m
@@ -29,6 +29,27 @@ - (NSDictionary*)fetchedPropertiesByName {
}
@end
+@interface NSEntityDescription (userInfoAdditions)
+- (BOOL)hasUserInfoKeys;
+- (NSDictionary *)userInfoByKeys;
+@end
+
+@implementation NSEntityDescription (userInfoAdditions)
+- (BOOL)hasUserInfoKeys {
+ return ([self.userInfo count] > 0);
+}
+
+- (NSDictionary *)userInfoByKeys
+{
+ NSMutableDictionary *userInfoByKeys = [NSMutableDictionary dictionary];
+
+ for (NSString *key in self.userInfo)
+ [userInfoByKeys setObject:[NSDictionary dictionaryWithObjectsAndKeys:key, @"key", [self.userInfo objectForKey:key], @"value", nil] forKey:key];
+
+ return userInfoByKeys;
+}
+@end
+
@implementation NSManagedObjectModel (entitiesWithACustomSubclassVerbose)
- (NSArray*)entitiesWithACustomSubclassInConfiguration:(NSString*)configuration_ verbose:(BOOL)verbose_ {
NSMutableArray *result = [NSMutableArray array];
@@ -161,6 +182,18 @@ - (NSArray*)noninheritedRelationships {
return [[[self relationshipsByName] allValues] sortedArrayUsingDescriptors:sortDescriptors];
}
}
+/** @TypeInfo NSEntityUserInfoDescription */
+- (NSArray*)userInfoKeyValues {
+ NSArray *sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"key" ascending:YES]];
+ NSEntityDescription *superentity = [self superentity];
+ if (superentity) {
+ NSMutableArray *result = [[[[self userInfoByKeys] allValues] mutableCopy] autorelease];
+ [result removeObjectsInArray:[[superentity userInfoByKeys] allValues]];
+ return [result sortedArrayUsingDescriptors:sortDescriptors];
+ } else {
+ return [[[self userInfoByKeys] allValues] sortedArrayUsingDescriptors:sortDescriptors];
+ }
+}
/** @TypeInfo NSFetchedPropertyDescription */
- (NSArray*)noninheritedFetchedProperties {
NSArray *sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]];
View
6 templates/machine.h.motemplate
@@ -23,6 +23,12 @@ extern const struct <$managedObjectClassName$>FetchedProperties {<$foreach Fetch
} <$managedObjectClassName$>FetchedProperties;
<$endif$>
+<$if hasUserInfoKeys$>
+extern const struct <$managedObjectClassName$>UserInfo {<$foreach UserInfo userInfoKeyValues do$>
+ <$if TemplateVar.arc$>__unsafe_unretained<$endif$> NSString *<$UserInfo.key$>;<$endforeach do$>
+} <$managedObjectClassName$>UserInfo;
+<$endif$>
+
<$foreach Relationship noninheritedRelationships do$>@class <$Relationship.destinationEntity.managedObjectClassName$>;
<$endforeach do$>
<$foreach Attribute noninheritedAttributes do$>
View
6 templates/machine.m.motemplate
@@ -21,6 +21,12 @@ const struct <$managedObjectClassName$>FetchedProperties <$managedObjectClassNam
};
<$endif$>
+<$if hasUserInfoKeys$>
+const struct <$managedObjectClassName$>UserInfo <$managedObjectClassName$>UserInfo = {<$foreach UserInfo userInfoKeyValues do$>
+ .<$UserInfo.key$> = @"<$UserInfo.value$>",<$endforeach do$>
+};
+<$endif$>
+
@implementation <$managedObjectClassName$>ID
@end
Please sign in to comment.
Something went wrong with that request. Please try again.