Skip to content

Commit

Permalink
[CHANGE] Remove machine.m implementations of to-many relationship set…
Browse files Browse the repository at this point in the history
…ters.

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.
  • Loading branch information
rentzsch committed Jan 4, 2010
1 parent fb7eb17 commit 665a8d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 35 deletions.
14 changes: 9 additions & 5 deletions templates/machine.h.motemplate
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
<$foreach Relationship noninheritedRelationships do$>
<$if Relationship.isToMany$>
@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;
<$else$>
@property (nonatomic, retain) <$Relationship.destinationEntity.managedObjectClassName$>* <$Relationship.name$>;
Expand All @@ -48,3 +43,12 @@
<$endif$>
<$endforeach do$>
@end

@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$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_;
- (void)remove<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_;
<$endif$><$endforeach do$>
@end
30 changes: 0 additions & 30 deletions templates/machine.m.motemplate
Original file line number Diff line number Diff line change
Expand Up @@ -41,42 +41,12 @@
@dynamic <$Relationship.name$>;

<$if Relationship.isToMany$>

- (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;
}

<$endif$>
<$endforeach do$>

Expand Down

0 comments on commit 665a8d6

Please sign in to comment.