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
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions mogenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ - (NSDictionary *)fetchedPropertiesByName
}
@end

@interface NSEntityDescription (userInfoAdditions)
- (NSDictionary *)userInfoByKeys;
@end

@implementation NSEntityDescription (userInfoAdditions)
- (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];
Expand Down Expand Up @@ -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.

- (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]];
Expand Down
4 changes: 4 additions & 0 deletions templates/machine.h.motemplate
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ extern const struct <$managedObjectClassName$>FetchedProperties {<$foreach Fetch
<$if TemplateVar.arc$>__unsafe_unretained<$endif$> NSString *<$FetchedProperty.name$>;<$endforeach do$>
} <$managedObjectClassName$>FetchedProperties;

extern const struct <$managedObjectClassName$>UserInfo {<$foreach UserInfo userInfoKeyValues do$>
<$if TemplateVar.arc$>__unsafe_unretained<$endif$> NSString *<$UserInfo.key$>;<$endforeach do$>
} <$managedObjectClassName$>UserInfo;

<$foreach Relationship noninheritedRelationships do$>@class <$Relationship.destinationEntity.managedObjectClassName$>;
<$endforeach do$>
<$foreach Attribute noninheritedAttributes do$><$if Attribute.hasTransformableAttributeType$>@class <$Attribute.objectAttributeClassName$>;<$endif$>
Expand Down
4 changes: 4 additions & 0 deletions templates/machine.m.motemplate
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const struct <$managedObjectClassName$>FetchedProperties <$managedObjectClassNam
.<$FetchedProperty.name$> = @"<$FetchedProperty.name$>",<$endforeach do$>
};

const struct <$managedObjectClassName$>UserInfo <$managedObjectClassName$>UserInfo {<$foreach UserInfo userInfoKeyValues do$>
.<$UserInfo.key$> = @"<$UserInfo.value$>",<$endforeach do$>
};

@implementation <$managedObjectClassName$>ID
@end

Expand Down