From 68e73da2be59f0ae3e60e32a45986aa7b9651a3c Mon Sep 17 00:00:00 2001 From: rentzsch Date: Fri, 9 Oct 2009 04:17:26 -0500 Subject: [PATCH] [NEW] Switch default machine templates to use @dynamic. Thus generated code now requires 10.5. Old non-@dynamic templates moved to contributed templates/rentzsch non-dynamic. (Pierre Bernard) --- .../rentzsch non-dynamic/human.h.motemplate | 5 + .../rentzsch non-dynamic/human.m.motemplate | 7 + .../rentzsch non-dynamic/machine.h.motemplate | 59 ++++++ .../rentzsch non-dynamic/machine.m.motemplate | 191 ++++++++++++++++++ mogenerator.m | 2 +- templates/machine.h.motemplate | 17 +- templates/machine.m.motemplate | 42 +--- 7 files changed, 269 insertions(+), 54 deletions(-) create mode 100644 contributed templates/rentzsch non-dynamic/human.h.motemplate create mode 100644 contributed templates/rentzsch non-dynamic/human.m.motemplate create mode 100644 contributed templates/rentzsch non-dynamic/machine.h.motemplate create mode 100644 contributed templates/rentzsch non-dynamic/machine.m.motemplate diff --git a/contributed templates/rentzsch non-dynamic/human.h.motemplate b/contributed templates/rentzsch non-dynamic/human.h.motemplate new file mode 100644 index 00000000..e3f3de05 --- /dev/null +++ b/contributed templates/rentzsch non-dynamic/human.h.motemplate @@ -0,0 +1,5 @@ +#import "_<$managedObjectClassName$>.h" + +@interface <$managedObjectClassName$> : _<$managedObjectClassName$> {} +// Custom logic goes here. +@end diff --git a/contributed templates/rentzsch non-dynamic/human.m.motemplate b/contributed templates/rentzsch non-dynamic/human.m.motemplate new file mode 100644 index 00000000..66fb9439 --- /dev/null +++ b/contributed templates/rentzsch non-dynamic/human.m.motemplate @@ -0,0 +1,7 @@ +#import "<$managedObjectClassName$>.h" + +@implementation <$managedObjectClassName$> + +// Custom logic goes here. + +@end diff --git a/contributed templates/rentzsch non-dynamic/machine.h.motemplate b/contributed templates/rentzsch non-dynamic/machine.h.motemplate new file mode 100644 index 00000000..37ed3edb --- /dev/null +++ b/contributed templates/rentzsch non-dynamic/machine.h.motemplate @@ -0,0 +1,59 @@ +// DO NOT EDIT. This file is machine-generated and constantly overwritten. +// Make changes to <$managedObjectClassName$>.h instead. + +#import +<$if hasCustomSuperentity$>#import "<$customSuperentity$>.h"<$endif$> + +<$foreach Relationship noninheritedRelationships do$>@class <$Relationship.destinationEntity.managedObjectClassName$>; +<$endforeach do$> +@interface <$managedObjectClassName$>ID : NSManagedObjectID {} +@end + +@interface _<$managedObjectClassName$> : <$customSuperentity$> {} ++ (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_; +- (<$managedObjectClassName$>ID*)objectID; + +<$foreach Attribute noninheritedAttributes do$> +<$if Attribute.hasDefinedAttributeType$> +- (<$Attribute.objectAttributeType$>*)<$Attribute.name$>; +- (void)set<$Attribute.name.initialCapitalString$>:(<$Attribute.objectAttributeType$>*)value_; +#if defined(MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 +@property (retain) <$Attribute.objectAttributeType$> *<$Attribute.name$>; +#endif +<$if Attribute.hasScalarAttributeType$> +- (<$Attribute.scalarAttributeType$>)<$Attribute.name$>Value; +- (void)set<$Attribute.name.initialCapitalString$>Value:(<$Attribute.scalarAttributeType$>)value_; +<$endif$> +//- (BOOL)validate<$Attribute.name.initialCapitalString$>:(id*)value_ error:(NSError**)error_; +<$endif$> +<$endforeach do$> +<$foreach Relationship noninheritedRelationships do$> +<$if Relationship.isToMany$> +- (NSSet*)<$Relationship.name$>; +- (void)add<$Relationship.name.initialCapitalString$>:(NSSet*)value_; +- (void)remove<$Relationship.name.initialCapitalString$>:(NSSet*)value_; +- (void)add<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_; +- (void)remove<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_; +- (NSMutableSet*)<$Relationship.name$>Set; +#if defined(MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 +@property (retain) NSSet* <$Relationship.name$>; +#endif +<$else$> +- (<$Relationship.destinationEntity.managedObjectClassName$>*)<$Relationship.name$>; +- (void)set<$Relationship.name.initialCapitalString$>:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_; +//- (BOOL)validate<$Relationship.name.initialCapitalString$>:(id*)value_ error:(NSError**)error_; +#if defined(MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 +@property (retain) <$Relationship.destinationEntity.managedObjectClassName$>* <$Relationship.name$>; +#endif +<$endif$> +<$endforeach do$> +<$foreach FetchRequest prettyFetchRequests do$> +<$if FetchRequest.singleResult$> ++ (id)fetch<$FetchRequest.name.initialCapitalString$>:(NSManagedObjectContext*)moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:(<$Binding.type$>)<$Binding.name$>_<$endforeach do2$>; ++ (id)fetch<$FetchRequest.name.initialCapitalString$>:(NSManagedObjectContext*)moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:(<$Binding.type$>)<$Binding.name$>_<$endforeach do2$> error:(NSError**)error_; +<$else$> ++ (NSArray*)fetch<$FetchRequest.name.initialCapitalString$>:(NSManagedObjectContext*)moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:(<$Binding.type$>)<$Binding.name$>_<$endforeach do2$>; ++ (NSArray*)fetch<$FetchRequest.name.initialCapitalString$>:(NSManagedObjectContext*)moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:(<$Binding.type$>)<$Binding.name$>_<$endforeach do2$> error:(NSError**)error_; +<$endif$> +<$endforeach do$> +@end diff --git a/contributed templates/rentzsch non-dynamic/machine.m.motemplate b/contributed templates/rentzsch non-dynamic/machine.m.motemplate new file mode 100644 index 00000000..ebce6604 --- /dev/null +++ b/contributed templates/rentzsch non-dynamic/machine.m.motemplate @@ -0,0 +1,191 @@ +// DO NOT EDIT. This file is machine-generated and constantly overwritten. +// Make changes to <$managedObjectClassName$>.m instead. + +#import "_<$managedObjectClassName$>.h" + +@implementation <$managedObjectClassName$>ID +@end + +@implementation _<$managedObjectClassName$> + ++ (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ { + return [NSEntityDescription insertNewObjectForEntityForName:@"<$name$>" inManagedObjectContext:moc_]; +} + +- (<$managedObjectClassName$>ID*)objectID { + return (<$managedObjectClassName$>ID*)[super objectID]; +} + +<$foreach Attribute noninheritedAttributes do$> +<$if Attribute.hasDefinedAttributeType$> + +- (<$Attribute.objectAttributeType$>*)<$Attribute.name$> { + [self willAccessValueForKey:@"<$Attribute.name$>"]; + <$Attribute.objectAttributeType$> *result = [self primitiveValueForKey:@"<$Attribute.name$>"]; + [self didAccessValueForKey:@"<$Attribute.name$>"]; + return result; +} + +- (void)set<$Attribute.name.initialCapitalString$>:(<$Attribute.objectAttributeType$>*)value_ { + [self willChangeValueForKey:@"<$Attribute.name$>"]; + [self setPrimitiveValue:value_ forKey:@"<$Attribute.name$>"]; + [self didChangeValueForKey:@"<$Attribute.name$>"]; +} + +<$if Attribute.hasScalarAttributeType$> + +- (<$Attribute.scalarAttributeType$>)<$Attribute.name$>Value { + NSNumber *result = [self <$Attribute.name$>]; + return result ? [result <$Attribute.scalarAttributeType.camelCaseString$>Value] : 0; +} + +- (void)set<$Attribute.name.initialCapitalString$>Value:(<$Attribute.scalarAttributeType$>)value_ { + [self set<$Attribute.name.initialCapitalString$>:[NSNumber numberWith<$Attribute.scalarAttributeType.camelCaseString.initialCapitalString$>:value_]]; +} + +<$endif$> +<$endif$> +<$endforeach do$> + +<$foreach Relationship noninheritedRelationships do$> + <$if Relationship.isToMany$> + +- (NSSet*)<$Relationship.name$> { + [self willAccessValueForKey:@"<$Relationship.name$>"]; + NSSet *result = [self primitiveValueForKey:@"<$Relationship.name$>"]; + [self didAccessValueForKey:@"<$Relationship.name$>"]; + return result; +} + +- (void)set<$Relationship.name.initialCapitalString$>:(NSSet*)value_ { + [self willChangeValueForKey:@"<$Relationship.name$>" withSetMutation:NSKeyValueSetSetMutation usingObjects:value_]; + [[self primitiveValueForKey:@"<$Relationship.name$>"] setSet:value_]; + [self didChangeValueForKey:@"<$Relationship.name$>" withSetMutation:NSKeyValueSetSetMutation usingObjects:value_]; +} + +- (void)add<$Relationship.name.initialCapitalString$>:(NSSet*)value_ { + [self willChangeValueForKey:@"<$Relationship.name$>" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value_]; + [[self primitiveValueForKey:@"<$Relationship.name$>"] unionSet:value_]; + [self didChangeValueForKey:@"<$Relationship.name$>" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value_]; +} + +-(void)remove<$Relationship.name.initialCapitalString$>:(NSSet*)value_ { + [self willChangeValueForKey:@"<$Relationship.name$>" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value_]; + [[self primitiveValueForKey:@"<$Relationship.name$>"] minusSet:value_]; + [self didChangeValueForKey:@"<$Relationship.name$>" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value_]; +} + +- (void)add<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_ { + NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value_ count:1]; + [self willChangeValueForKey:@"<$Relationship.name$>" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects]; + [[self primitiveValueForKey:@"<$Relationship.name$>"] addObject:value_]; + [self didChangeValueForKey:@"<$Relationship.name$>" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects]; + [changedObjects release]; +} + +- (void)remove<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_ { + NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value_ count:1]; + [self willChangeValueForKey:@"<$Relationship.name$>" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects]; + [[self primitiveValueForKey:@"<$Relationship.name$>"] removeObject:value_]; + [self didChangeValueForKey:@"<$Relationship.name$>" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects]; + [changedObjects release]; +} + +- (NSMutableSet*)<$Relationship.name$>Set { + [self willAccessValueForKey:@"<$Relationship.name$>"]; + NSMutableSet *result = [self mutableSetValueForKey:@"<$Relationship.name$>"]; + [self didAccessValueForKey:@"<$Relationship.name$>"]; + return result; +} + <$else$> + +- (<$Relationship.destinationEntity.managedObjectClassName$>*)<$Relationship.name$> { + [self willAccessValueForKey:@"<$Relationship.name$>"]; + <$Relationship.destinationEntity.managedObjectClassName$> *result = [self primitiveValueForKey:@"<$Relationship.name$>"]; + [self didAccessValueForKey:@"<$Relationship.name$>"]; + return result; +} + +- (void)set<$Relationship.name.initialCapitalString$>:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_ { + [self willChangeValueForKey:@"<$Relationship.name$>"]; + [self setPrimitiveValue:value_ forKey:@"<$Relationship.name$>"]; + [self didChangeValueForKey:@"<$Relationship.name$>"]; +} + + <$endif$> +<$endforeach do$> + +<$foreach FetchRequest prettyFetchRequests do$> +<$if FetchRequest.singleResult$> ++ (id)fetch<$FetchRequest.name.initialCapitalString$>:(NSManagedObjectContext*)moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:(<$Binding.type$>)<$Binding.name$>_<$endforeach do2$> { + NSError *error = nil; + id result = [self fetch<$FetchRequest.name.initialCapitalString$>:moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:<$Binding.name$>_<$endforeach do2$> error:&error]; + if (error) { + [NSApp presentError:error]; + } + return result; +} ++ (id)fetch<$FetchRequest.name.initialCapitalString$>:(NSManagedObjectContext*)moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:(<$Binding.type$>)<$Binding.name$>_<$endforeach do2$> error:(NSError**)error_ { + NSError *error = nil; + + NSManagedObjectModel *model = [[moc_ persistentStoreCoordinator] managedObjectModel]; + NSDictionary *substitutionVariables = [NSDictionary dictionaryWithObjectsAndKeys: + <$foreach Binding FetchRequest.bindings do2$> + <$Binding.name$>_, @"<$Binding.name$>", + <$endforeach do2$> + nil]; + NSFetchRequest *fetchRequest = [model fetchRequestFromTemplateWithName:@"<$FetchRequest.name$>" + substitutionVariables:substitutionVariables]; + NSAssert(fetchRequest, @"Can't find fetch request named \"<$FetchRequest.name$>\"."); + + id result = nil; + NSArray *results = [moc_ executeFetchRequest:fetchRequest error:&error]; + + if (!error) { + switch ([results count]) { + case 0: + // Nothing found matching the fetch request. That's cool, though: we'll just return nil. + break; + case 1: + result = [results objectAtIndex:0]; + break; + default: + NSLog(@"WARN fetch request <$FetchRequest.name$>: 0 or 1 objects expected, %u found (substitutionVariables:%@, results:%@)", + [results count], + substitutionVariables, + results); + } + } + + if (error_) *error_ = error; + return result; +} +<$else$> ++ (NSArray*)fetch<$FetchRequest.name.initialCapitalString$>:(NSManagedObjectContext*)moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:(<$Binding.type$>)<$Binding.name$>_<$endforeach do2$> { + NSError *error = nil; + NSArray *result = [self fetch<$FetchRequest.name.initialCapitalString$>:moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:<$Binding.name$>_<$endforeach do2$> error:&error]; + if (error) { + [NSApp presentError:error]; + } + return result; +} ++ (NSArray*)fetch<$FetchRequest.name.initialCapitalString$>:(NSManagedObjectContext*)moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:(<$Binding.type$>)<$Binding.name$>_<$endforeach do2$> error:(NSError**)error_ { + NSError *error = nil; + + NSManagedObjectModel *model = [[moc_ persistentStoreCoordinator] managedObjectModel]; + NSFetchRequest *fetchRequest = [model fetchRequestFromTemplateWithName:@"<$FetchRequest.name$>" + substitutionVariables:[NSDictionary dictionaryWithObjectsAndKeys: + <$foreach Binding FetchRequest.bindings do2$> + <$Binding.name$>_, @"<$Binding.name$>", + <$endforeach do2$> + nil] + ]; + NSAssert(fetchRequest, @"Can't find fetch request named \"<$FetchRequest.name$>\"."); + + NSArray *result = [moc_ executeFetchRequest:fetchRequest error:&error]; + if (error_) *error_ = error; + return result; +} +<$endif$> +<$endforeach do$> +@end diff --git a/mogenerator.m b/mogenerator.m index ba251030..d7de585c 100644 --- a/mogenerator.m +++ b/mogenerator.m @@ -75,7 +75,7 @@ - (void)_processPredicate:(NSPredicate*)predicate_ bindings:(NSMutableArray*)bin nsenumerate([(NSCompoundPredicate*)predicate_ subpredicates], NSPredicate, subpredicate) { [self _processPredicate:subpredicate bindings:bindings_]; } - } else { + } else if ([predicate_ isKindOfClass:[NSComparisonPredicate class]]) { assert([[(NSComparisonPredicate*)predicate_ leftExpression] expressionType] == NSKeyPathExpressionType); NSExpression *lhs = [(NSComparisonPredicate*)predicate_ leftExpression]; NSExpression *rhs = [(NSComparisonPredicate*)predicate_ rightExpression]; diff --git a/templates/machine.h.motemplate b/templates/machine.h.motemplate index 37ed3edb..8216c1be 100644 --- a/templates/machine.h.motemplate +++ b/templates/machine.h.motemplate @@ -15,11 +15,7 @@ <$foreach Attribute noninheritedAttributes do$> <$if Attribute.hasDefinedAttributeType$> -- (<$Attribute.objectAttributeType$>*)<$Attribute.name$>; -- (void)set<$Attribute.name.initialCapitalString$>:(<$Attribute.objectAttributeType$>*)value_; -#if defined(MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 -@property (retain) <$Attribute.objectAttributeType$> *<$Attribute.name$>; -#endif +@property (nonatomic, retain) <$Attribute.objectAttributeType$> *<$Attribute.name$>; <$if Attribute.hasScalarAttributeType$> - (<$Attribute.scalarAttributeType$>)<$Attribute.name$>Value; - (void)set<$Attribute.name.initialCapitalString$>Value:(<$Attribute.scalarAttributeType$>)value_; @@ -29,22 +25,15 @@ <$endforeach do$> <$foreach Relationship noninheritedRelationships do$> <$if Relationship.isToMany$> -- (NSSet*)<$Relationship.name$>; +@property (nonatomic, retain) NSSet* <$Relationship.name$>; + - (void)add<$Relationship.name.initialCapitalString$>:(NSSet*)value_; - (void)remove<$Relationship.name.initialCapitalString$>:(NSSet*)value_; - (void)add<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_; - (void)remove<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_; - (NSMutableSet*)<$Relationship.name$>Set; -#if defined(MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 -@property (retain) NSSet* <$Relationship.name$>; -#endif <$else$> -- (<$Relationship.destinationEntity.managedObjectClassName$>*)<$Relationship.name$>; -- (void)set<$Relationship.name.initialCapitalString$>:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_; //- (BOOL)validate<$Relationship.name.initialCapitalString$>:(id*)value_ error:(NSError**)error_; -#if defined(MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 -@property (retain) <$Relationship.destinationEntity.managedObjectClassName$>* <$Relationship.name$>; -#endif <$endif$> <$endforeach do$> <$foreach FetchRequest prettyFetchRequests do$> diff --git a/templates/machine.m.motemplate b/templates/machine.m.motemplate index ebce6604..5e5984ce 100644 --- a/templates/machine.m.motemplate +++ b/templates/machine.m.motemplate @@ -19,18 +19,7 @@ <$foreach Attribute noninheritedAttributes do$> <$if Attribute.hasDefinedAttributeType$> -- (<$Attribute.objectAttributeType$>*)<$Attribute.name$> { - [self willAccessValueForKey:@"<$Attribute.name$>"]; - <$Attribute.objectAttributeType$> *result = [self primitiveValueForKey:@"<$Attribute.name$>"]; - [self didAccessValueForKey:@"<$Attribute.name$>"]; - return result; -} - -- (void)set<$Attribute.name.initialCapitalString$>:(<$Attribute.objectAttributeType$>*)value_ { - [self willChangeValueForKey:@"<$Attribute.name$>"]; - [self setPrimitiveValue:value_ forKey:@"<$Attribute.name$>"]; - [self didChangeValueForKey:@"<$Attribute.name$>"]; -} +@dynamic <$Attribute.name$>; <$if Attribute.hasScalarAttributeType$> @@ -48,20 +37,9 @@ <$endforeach do$> <$foreach Relationship noninheritedRelationships do$> - <$if Relationship.isToMany$> - -- (NSSet*)<$Relationship.name$> { - [self willAccessValueForKey:@"<$Relationship.name$>"]; - NSSet *result = [self primitiveValueForKey:@"<$Relationship.name$>"]; - [self didAccessValueForKey:@"<$Relationship.name$>"]; - return result; -} +@dynamic <$Relationship.name$>; -- (void)set<$Relationship.name.initialCapitalString$>:(NSSet*)value_ { - [self willChangeValueForKey:@"<$Relationship.name$>" withSetMutation:NSKeyValueSetSetMutation usingObjects:value_]; - [[self primitiveValueForKey:@"<$Relationship.name$>"] setSet:value_]; - [self didChangeValueForKey:@"<$Relationship.name$>" withSetMutation:NSKeyValueSetSetMutation usingObjects:value_]; -} + <$if Relationship.isToMany$> - (void)add<$Relationship.name.initialCapitalString$>:(NSSet*)value_ { [self willChangeValueForKey:@"<$Relationship.name$>" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value_]; @@ -97,20 +75,6 @@ [self didAccessValueForKey:@"<$Relationship.name$>"]; return result; } - <$else$> - -- (<$Relationship.destinationEntity.managedObjectClassName$>*)<$Relationship.name$> { - [self willAccessValueForKey:@"<$Relationship.name$>"]; - <$Relationship.destinationEntity.managedObjectClassName$> *result = [self primitiveValueForKey:@"<$Relationship.name$>"]; - [self didAccessValueForKey:@"<$Relationship.name$>"]; - return result; -} - -- (void)set<$Relationship.name.initialCapitalString$>:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_ { - [self willChangeValueForKey:@"<$Relationship.name$>"]; - [self setPrimitiveValue:value_ forKey:@"<$Relationship.name$>"]; - [self didChangeValueForKey:@"<$Relationship.name$>"]; -} <$endif$> <$endforeach do$>