Skip to content
This repository
Browse code

[NEW] Support for ordered relationships.

  • Loading branch information...
commit 4e9a045dcbf5af2eefed2ca9cb5fbac8394f9df2 1 parent 88ab27b
Jonathan 'Wolf' Rentzsch authored July 01, 2011
10  mogenerator.h
@@ -20,7 +20,6 @@
20 20
 - (NSArray*)entitiesWithACustomSubclassVerbose:(BOOL)verbose_;
21 21
 @end
22 22
 
23  
-
24 23
 @interface NSEntityDescription (customBaseClass)
25 24
 - (BOOL)hasCustomSuperentity;
26 25
 - (NSString*)customSuperentity;
@@ -36,6 +35,15 @@
36 35
 - (BOOL)hasTransformableAttributeType;
37 36
 @end
38 37
 
  38
+@interface NSRelationshipDescription (collectionClassName)
  39
+- (NSString*)mutableCollectionClassName;
  40
+- (NSString*)immutableCollectionClassName;
  41
+- (BOOL)_jr_isOrdered;
  42
+@end
  43
+@interface NSObject (JustHereToSuppressIsOrderedNotImplementedCompilerWarning)
  44
+- (BOOL)isOrdered;
  45
+@end
  46
+
39 47
 @interface NSString (camelCaseString)
40 48
 - (NSString*)camelCaseString;
41 49
 @end
20  mogenerator.m
@@ -261,6 +261,26 @@ - (BOOL)hasTransformableAttributeType {
261 261
 
262 262
 @end
263 263
 
  264
+@implementation NSRelationshipDescription (collectionClassName)
  265
+
  266
+- (NSString*)mutableCollectionClassName {
  267
+	return [self _jr_isOrdered] ? @"NSMutableOrderedSet" : @"NSMutableSet";
  268
+}
  269
+
  270
+- (NSString*)immutableCollectionClassName {
  271
+	return [self _jr_isOrdered] ? @"NSOrderedSet" : @"NSSet";
  272
+}
  273
+
  274
+- (BOOL)_jr_isOrdered {
  275
+	if ([self respondsToSelector:@selector(isOrdered)]) {
  276
+        return [self isOrdered];
  277
+    } else {
  278
+        return NO;
  279
+    }
  280
+}
  281
+
  282
+@end
  283
+
264 284
 @implementation NSString (camelCaseString)
265 285
 - (NSString*)camelCaseString {
266 286
 	NSArray *lowerCasedWordArray = [[self wordArray] arrayByMakingObjectsPerformSelector:@selector(lowercaseString)];
14  templates/machine.h.motemplate
@@ -35,11 +35,11 @@
35 35
 <$foreach Relationship noninheritedRelationships do$>
36 36
 <$if Relationship.isToMany$>
37 37
 <$if TemplateVar.arc$>
38  
-@property (nonatomic, strong) NSSet* <$Relationship.name$>;
  38
+@property (nonatomic, strong) <$Relationship.immutableCollectionClassName$>* <$Relationship.name$>;
39 39
 <$else$>
40  
-@property (nonatomic, retain) NSSet* <$Relationship.name$>;
  40
+@property (nonatomic, retain) <$Relationship.immutableCollectionClassName$>* <$Relationship.name$>;
41 41
 <$endif$>
42  
-- (NSMutableSet*)<$Relationship.name$>Set;
  42
+- (<$Relationship.mutableCollectionClassName$>*)<$Relationship.name$>Set;
43 43
 <$else$>
44 44
 <$if TemplateVar.arc$>
45 45
 @property (nonatomic, strong) <$Relationship.destinationEntity.managedObjectClassName$>* <$Relationship.name$>;
@@ -65,8 +65,8 @@
65 65
 
66 66
 @interface _<$managedObjectClassName$> (CoreDataGeneratedAccessors)
67 67
 <$foreach Relationship noninheritedRelationships do$><$if Relationship.isToMany$>
68  
-- (void)add<$Relationship.name.initialCapitalString$>:(NSSet*)value_;
69  
-- (void)remove<$Relationship.name.initialCapitalString$>:(NSSet*)value_;
  68
+- (void)add<$Relationship.name.initialCapitalString$>:(<$Relationship.immutableCollectionClassName$>*)value_;
  69
+- (void)remove<$Relationship.name.initialCapitalString$>:(<$Relationship.immutableCollectionClassName$>*)value_;
70 70
 - (void)add<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_;
71 71
 - (void)remove<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_;
72 72
 <$endif$><$endforeach do$>
@@ -85,8 +85,8 @@
85 85
 <$endforeach do$>
86 86
 <$foreach Relationship noninheritedRelationships do$>
87 87
 <$if Relationship.isToMany$>
88  
-- (NSMutableSet*)primitive<$Relationship.name.initialCapitalString$>;
89  
-- (void)setPrimitive<$Relationship.name.initialCapitalString$>:(NSMutableSet*)value;
  88
+- (<$Relationship.mutableCollectionClassName$>*)primitive<$Relationship.name.initialCapitalString$>;
  89
+- (void)setPrimitive<$Relationship.name.initialCapitalString$>:(<$Relationship.mutableCollectionClassName$>*)value;
90 90
 <$else$>
91 91
 - (<$Relationship.destinationEntity.managedObjectClassName$>*)primitive<$Relationship.name.initialCapitalString$>;
92 92
 - (void)setPrimitive<$Relationship.name.initialCapitalString$>:(<$Relationship.destinationEntity.managedObjectClassName$>*)value;
10  templates/machine.m.motemplate
@@ -26,11 +26,11 @@
26 26
 	return (<$managedObjectClassName$>ID*)[super objectID];
27 27
 }
28 28
 
29  
-+ (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
30  
-	NSSet *keyPaths = [super keyPathsForValuesAffectingValueForKey:key];
  29
++ (<$Relationship.immutableCollectionClassName$> *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
  30
+	<$Relationship.immutableCollectionClassName$> *keyPaths = [super keyPathsForValuesAffectingValueForKey:key];
31 31
 	<$foreach Attribute noninheritedAttributes do$><$if Attribute.hasDefinedAttributeType$><$if Attribute.hasScalarAttributeType$>
32 32
 	if ([key isEqualToString:@"<$Attribute.name$>Value"]) {
33  
-		NSSet *affectingKey = [NSSet setWithObject:@"<$Attribute.name$>"];
  33
+		<$Relationship.immutableCollectionClassName$> *affectingKey = [<$Relationship.immutableCollectionClassName$> setWithObject:@"<$Attribute.name$>"];
34 34
 		keyPaths = [keyPaths setByAddingObjectsFromSet:affectingKey];
35 35
 	}<$endif$><$endif$><$endforeach do$>
36 36
 
@@ -69,9 +69,9 @@
69 69
 @dynamic <$Relationship.name$>;
70 70
 
71 71
 	<$if Relationship.isToMany$>
72  
-- (NSMutableSet*)<$Relationship.name$>Set {
  72
+- (<$Relationship.mutableCollectionClassName$>*)<$Relationship.name$>Set {
73 73
 	[self willAccessValueForKey:@"<$Relationship.name$>"];
74  
-	NSMutableSet *result = [self mutableSetValueForKey:@"<$Relationship.name$>"];
  74
+	<$Relationship.mutableCollectionClassName$> *result = [self mutableSetValueForKey:@"<$Relationship.name$>"];
75 75
 	[self didAccessValueForKey:@"<$Relationship.name$>"];
76 76
 	return result;
77 77
 }

0 notes on commit 4e9a045

Please sign in to comment.
Something went wrong with that request. Please try again.