Skip to content

Commit

Permalink
- Added support for fetched properties
Browse files Browse the repository at this point in the history
- To generate @Property declarations for fetched properties in mogenerator templates, use the following template code:
	<$foreach FetchedProperty noninheritedFetchedProperties do$>
	@Property (nonatomic, readonly) NSArray *<$FetchedProperty.name$>;
	<$endif$><$endif$><$endforeach do$>
  • Loading branch information
nikita-zhuk authored and rentzsch committed Jun 2, 2010
1 parent 015aa0b commit 7481add
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions mogenerator.m
Expand Up @@ -10,6 +10,25 @@

NSString *gCustomBaseClass;

@interface NSEntityDescription (fetchedPropertiesAdditions)
- (NSDictionary *)fetchedPropertiesByName;
@end

@implementation NSEntityDescription (fetchedPropertiesAdditions)
- (NSDictionary *)fetchedPropertiesByName
{
NSMutableDictionary *fetchedPropertiesByName = [NSMutableDictionary dictionary];

for (NSPropertyDescription *property in [self properties])
{
if([property isKindOfClass:[NSFetchedPropertyDescription class]])
[fetchedPropertiesByName setObject:property forKey:[property name]];
}

return fetchedPropertiesByName;
}
@end

@implementation NSManagedObjectModel (entitiesWithACustomSubclassVerbose)
- (NSArray*)entitiesWithACustomSubclassVerbose:(BOOL)verbose_ {
NSMutableArray *result = [NSMutableArray array];
Expand Down Expand Up @@ -76,6 +95,17 @@ - (NSArray*)noninheritedRelationships {
return [[self relationshipsByName] allValues];
}
}
/** @TypeInfo NSFetchedPropertyDescription */
- (NSArray*)noninheritedFetchedProperties {
NSEntityDescription *superentity = [self superentity];
if (superentity) {
NSMutableArray *result = [[[[self fetchedPropertiesByName] allValues] mutableCopy] autorelease];
[result removeObjectsInArray:[[superentity fetchedPropertiesByName] allValues]];
return result;
} else {
return [[self fetchedPropertiesByName] allValues];
}
}

#pragma mark Fetch Request support

Expand Down

0 comments on commit 7481add

Please sign in to comment.