Permalink
Browse files

- Added support for fetched properties

- 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...
1 parent 015aa0b commit 7481add810ef798c0f678d782d7d8fb9e6ff4d46 @nikita-zhuk nikita-zhuk committed with Jun 2, 2010
Showing with 30 additions and 0 deletions.
  1. +30 −0 mogenerator.m
View
@@ -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];
@@ -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

0 comments on commit 7481add

Please sign in to comment.