Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[NEW] Support for ordered relationships.

  • Loading branch information...
commit 4e9a045dcbf5af2eefed2ca9cb5fbac8394f9df2 1 parent 88ab27b
Jonathan 'Wolf' Rentzsch authored
10 mogenerator.h
View
@@ -20,7 +20,6 @@
- (NSArray*)entitiesWithACustomSubclassVerbose:(BOOL)verbose_;
@end
-
@interface NSEntityDescription (customBaseClass)
- (BOOL)hasCustomSuperentity;
- (NSString*)customSuperentity;
@@ -36,6 +35,15 @@
- (BOOL)hasTransformableAttributeType;
@end
+@interface NSRelationshipDescription (collectionClassName)
+- (NSString*)mutableCollectionClassName;
+- (NSString*)immutableCollectionClassName;
+- (BOOL)_jr_isOrdered;
+@end
+@interface NSObject (JustHereToSuppressIsOrderedNotImplementedCompilerWarning)
+- (BOOL)isOrdered;
+@end
+
@interface NSString (camelCaseString)
- (NSString*)camelCaseString;
@end
20 mogenerator.m
View
@@ -261,6 +261,26 @@ - (BOOL)hasTransformableAttributeType {
@end
+@implementation NSRelationshipDescription (collectionClassName)
+
+- (NSString*)mutableCollectionClassName {
+ return [self _jr_isOrdered] ? @"NSMutableOrderedSet" : @"NSMutableSet";
+}
+
+- (NSString*)immutableCollectionClassName {
+ return [self _jr_isOrdered] ? @"NSOrderedSet" : @"NSSet";
+}
+
+- (BOOL)_jr_isOrdered {
+ if ([self respondsToSelector:@selector(isOrdered)]) {
+ return [self isOrdered];
+ } else {
+ return NO;
+ }
+}
+
+@end
+
@implementation NSString (camelCaseString)
- (NSString*)camelCaseString {
NSArray *lowerCasedWordArray = [[self wordArray] arrayByMakingObjectsPerformSelector:@selector(lowercaseString)];
14 templates/machine.h.motemplate
View
@@ -35,11 +35,11 @@
<$foreach Relationship noninheritedRelationships do$>
<$if Relationship.isToMany$>
<$if TemplateVar.arc$>
-@property (nonatomic, strong) NSSet* <$Relationship.name$>;
+@property (nonatomic, strong) <$Relationship.immutableCollectionClassName$>* <$Relationship.name$>;
<$else$>
-@property (nonatomic, retain) NSSet* <$Relationship.name$>;
+@property (nonatomic, retain) <$Relationship.immutableCollectionClassName$>* <$Relationship.name$>;
<$endif$>
-- (NSMutableSet*)<$Relationship.name$>Set;
+- (<$Relationship.mutableCollectionClassName$>*)<$Relationship.name$>Set;
<$else$>
<$if TemplateVar.arc$>
@property (nonatomic, strong) <$Relationship.destinationEntity.managedObjectClassName$>* <$Relationship.name$>;
@@ -65,8 +65,8 @@
@interface _<$managedObjectClassName$> (CoreDataGeneratedAccessors)
<$foreach Relationship noninheritedRelationships do$><$if Relationship.isToMany$>
-- (void)add<$Relationship.name.initialCapitalString$>:(NSSet*)value_;
-- (void)remove<$Relationship.name.initialCapitalString$>:(NSSet*)value_;
+- (void)add<$Relationship.name.initialCapitalString$>:(<$Relationship.immutableCollectionClassName$>*)value_;
+- (void)remove<$Relationship.name.initialCapitalString$>:(<$Relationship.immutableCollectionClassName$>*)value_;
- (void)add<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_;
- (void)remove<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_;
<$endif$><$endforeach do$>
@@ -85,8 +85,8 @@
<$endforeach do$>
<$foreach Relationship noninheritedRelationships do$>
<$if Relationship.isToMany$>
-- (NSMutableSet*)primitive<$Relationship.name.initialCapitalString$>;
-- (void)setPrimitive<$Relationship.name.initialCapitalString$>:(NSMutableSet*)value;
+- (<$Relationship.mutableCollectionClassName$>*)primitive<$Relationship.name.initialCapitalString$>;
+- (void)setPrimitive<$Relationship.name.initialCapitalString$>:(<$Relationship.mutableCollectionClassName$>*)value;
<$else$>
- (<$Relationship.destinationEntity.managedObjectClassName$>*)primitive<$Relationship.name.initialCapitalString$>;
- (void)setPrimitive<$Relationship.name.initialCapitalString$>:(<$Relationship.destinationEntity.managedObjectClassName$>*)value;
10 templates/machine.m.motemplate
View
@@ -26,11 +26,11 @@
return (<$managedObjectClassName$>ID*)[super objectID];
}
-+ (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
- NSSet *keyPaths = [super keyPathsForValuesAffectingValueForKey:key];
++ (<$Relationship.immutableCollectionClassName$> *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
+ <$Relationship.immutableCollectionClassName$> *keyPaths = [super keyPathsForValuesAffectingValueForKey:key];
<$foreach Attribute noninheritedAttributes do$><$if Attribute.hasDefinedAttributeType$><$if Attribute.hasScalarAttributeType$>
if ([key isEqualToString:@"<$Attribute.name$>Value"]) {
- NSSet *affectingKey = [NSSet setWithObject:@"<$Attribute.name$>"];
+ <$Relationship.immutableCollectionClassName$> *affectingKey = [<$Relationship.immutableCollectionClassName$> setWithObject:@"<$Attribute.name$>"];
keyPaths = [keyPaths setByAddingObjectsFromSet:affectingKey];
}<$endif$><$endif$><$endforeach do$>
@@ -69,9 +69,9 @@
@dynamic <$Relationship.name$>;
<$if Relationship.isToMany$>
-- (NSMutableSet*)<$Relationship.name$>Set {
+- (<$Relationship.mutableCollectionClassName$>*)<$Relationship.name$>Set {
[self willAccessValueForKey:@"<$Relationship.name$>"];
- NSMutableSet *result = [self mutableSetValueForKey:@"<$Relationship.name$>"];
+ <$Relationship.mutableCollectionClassName$> *result = [self mutableSetValueForKey:@"<$Relationship.name$>"];
[self didAccessValueForKey:@"<$Relationship.name$>"];
return result;
}
Please sign in to comment.
Something went wrong with that request. Please try again.