Skip to content

Commit 665a8d6

Browse files
committedJan 4, 2010
[CHANGE] Remove machine.m implementations of to-many relationship setters.
Mike Abdullah pointed out in http://www.mac-developer-network.com/columns/coredata/coredatajan10/ that Core Data on 10.5 and iPhone dynamically supply to-many relationship setters, so there's no reason to carry our own implementation. That's code that looks like this: - (void)addChildren:(NSSet*)value_ { [self willChangeValueForKey:@"children" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value_]; [[self primitiveValueForKey:@"children"] unionSet:value_]; [self didChangeValueForKey:@"children" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value_]; } -(void)removeChildren:(NSSet*)value_ { [self willChangeValueForKey:@"children" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value_]; [[self primitiveValueForKey:@"children"] minusSet:value_]; [self didChangeValueForKey:@"children" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value_]; } - (void)addChildrenObject:(ChildMO*)value_ { NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value_ count:1]; [self willChangeValueForKey:@"children" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects]; [[self primitiveValueForKey:@"children"] addObject:value_]; [self didChangeValueForKey:@"children" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects]; [changedObjects release]; } - (void)removeChildrenObject:(ChildMO*)value_ { NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value_ count:1]; [self willChangeValueForKey:@"children" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects]; [[self primitiveValueForKey:@"children"] removeObject:value_]; [self didChangeValueForKey:@"children" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects]; [changedObjects release]; } I've deleted the machine.m code and moved the method declarations into a category named $_CLASS_NAME(CoreDataGeneratedAccessors) in machine.h to avoid "method not implemented" build warnings. It probably would be nice to upgrade "contributed templates/rentzsch non-dynamic" to do the same (placing the machine.m code in if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 endif blocks) but I'm not going to for this commit.
1 parent fb7eb17 commit 665a8d6

File tree

2 files changed

+9
-35
lines changed

2 files changed

+9
-35
lines changed
 

‎templates/machine.h.motemplate

+9-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@
2727
<$foreach Relationship noninheritedRelationships do$>
2828
<$if Relationship.isToMany$>
2929
@property (nonatomic, retain) NSSet* <$Relationship.name$>;
30-
31-
- (void)add<$Relationship.name.initialCapitalString$>:(NSSet*)value_;
32-
- (void)remove<$Relationship.name.initialCapitalString$>:(NSSet*)value_;
33-
- (void)add<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_;
34-
- (void)remove<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_;
3530
- (NSMutableSet*)<$Relationship.name$>Set;
3631
<$else$>
3732
@property (nonatomic, retain) <$Relationship.destinationEntity.managedObjectClassName$>* <$Relationship.name$>;
@@ -48,3 +43,12 @@
4843
<$endif$>
4944
<$endforeach do$>
5045
@end
46+
47+
@interface _<$managedObjectClassName$> (CoreDataGeneratedAccessors)
48+
<$foreach Relationship noninheritedRelationships do$><$if Relationship.isToMany$>
49+
- (void)add<$Relationship.name.initialCapitalString$>:(NSSet*)value_;
50+
- (void)remove<$Relationship.name.initialCapitalString$>:(NSSet*)value_;
51+
- (void)add<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_;
52+
- (void)remove<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_;
53+
<$endif$><$endforeach do$>
54+
@end

‎templates/machine.m.motemplate

-30
Original file line numberDiff line numberDiff line change
@@ -41,42 +41,12 @@
4141
@dynamic <$Relationship.name$>;
4242

4343
<$if Relationship.isToMany$>
44-
45-
- (void)add<$Relationship.name.initialCapitalString$>:(NSSet*)value_ {
46-
[self willChangeValueForKey:@"<$Relationship.name$>" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value_];
47-
[[self primitiveValueForKey:@"<$Relationship.name$>"] unionSet:value_];
48-
[self didChangeValueForKey:@"<$Relationship.name$>" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value_];
49-
}
50-
51-
-(void)remove<$Relationship.name.initialCapitalString$>:(NSSet*)value_ {
52-
[self willChangeValueForKey:@"<$Relationship.name$>" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value_];
53-
[[self primitiveValueForKey:@"<$Relationship.name$>"] minusSet:value_];
54-
[self didChangeValueForKey:@"<$Relationship.name$>" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value_];
55-
}
56-
57-
- (void)add<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_ {
58-
NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value_ count:1];
59-
[self willChangeValueForKey:@"<$Relationship.name$>" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
60-
[[self primitiveValueForKey:@"<$Relationship.name$>"] addObject:value_];
61-
[self didChangeValueForKey:@"<$Relationship.name$>" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
62-
[changedObjects release];
63-
}
64-
65-
- (void)remove<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_ {
66-
NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value_ count:1];
67-
[self willChangeValueForKey:@"<$Relationship.name$>" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];
68-
[[self primitiveValueForKey:@"<$Relationship.name$>"] removeObject:value_];
69-
[self didChangeValueForKey:@"<$Relationship.name$>" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];
70-
[changedObjects release];
71-
}
72-
7344
- (NSMutableSet*)<$Relationship.name$>Set {
7445
[self willAccessValueForKey:@"<$Relationship.name$>"];
7546
NSMutableSet *result = [self mutableSetValueForKey:@"<$Relationship.name$>"];
7647
[self didAccessValueForKey:@"<$Relationship.name$>"];
7748
return result;
7849
}
79-
8050
<$endif$>
8151
<$endforeach do$>
8252

0 commit comments

Comments
 (0)
Please sign in to comment.