diff --git a/templates/machine.h.motemplate b/templates/machine.h.motemplate index 6d1cc200..1b9d01e0 100644 --- a/templates/machine.h.motemplate +++ b/templates/machine.h.motemplate @@ -122,19 +122,16 @@ extern const struct <$managedObjectClassName$>UserInfo {<$foreach UserInfo userI - (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_; - <$if Relationship.isOrdered$> -- (void)insertObject:(<$Relationship.immutableCollectionClassName$>*)value in<$Relationship.name.initialCapitalString$>AtIndex:(NSUInteger)idx; +- (void)insertObject:(<$Relationship.destinationEntity.managedObjectClassName$>*)value in<$Relationship.name.initialCapitalString$>AtIndex:(NSUInteger)idx; - (void)removeObjectFrom<$Relationship.name.initialCapitalString$>AtIndex:(NSUInteger)idx; - (void)insert<$Relationship.name.initialCapitalString$>:(NSArray *)value atIndexes:(NSIndexSet *)indexes; - (void)remove<$Relationship.name.initialCapitalString$>AtIndexes:(NSIndexSet *)indexes; -- (void)replaceObjectIn<$Relationship.name.initialCapitalString$>AtIndex:(NSUInteger)idx withObject:(<$Relationship.immutableCollectionClassName$>*)value; +- (void)replaceObjectIn<$Relationship.name.initialCapitalString$>AtIndex:(NSUInteger)idx withObject:(<$Relationship.destinationEntity.managedObjectClassName$>*)value; - (void)replace<$Relationship.name.initialCapitalString$>AtIndexes:(NSIndexSet *)indexes with<$Relationship.name.initialCapitalString$>:(NSArray *)values; <$endif$> - @end <$endif$> - <$endforeach do$> @interface _<$managedObjectClassName$> (CoreDataGeneratedPrimitiveAccessors) diff --git a/templates/machine.m.motemplate b/templates/machine.m.motemplate index d48f3aef..24c38857 100644 --- a/templates/machine.m.motemplate +++ b/templates/machine.m.motemplate @@ -243,23 +243,50 @@ const struct <$managedObjectClassName$>UserInfo <$managedObjectClassName$>UserIn - (void)remove<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_ { [self.<$Relationship.name$>Set removeObject:value_]; } -- (void)insertObject:(<$Relationship.immutableCollectionClassName$>*)value in<$Relationship.name.initialCapitalString$>AtIndex:(NSUInteger)idx { - [self.<$Relationship.name$>Set insertObject:value atIndex:idx]; +- (void)insertObject:(<$Relationship.destinationEntity.managedObjectClassName$>*)value in<$Relationship.name.initialCapitalString$>AtIndex:(NSUInteger)idx { + NSIndexSet* indexes = [NSIndexSet indexSetWithIndex:idx]; + [self willChange:NSKeyValueChangeInsertion valuesAtIndexes:indexes forKey:@"<$Relationship.name$>"]; + NSMutableOrderedSet *tmpOrderedSet = [NSMutableOrderedSet orderedSetWithOrderedSet:[self <$Relationship.name$>]]; + [tmpOrderedSet insertObject:value atIndex:idx]; + [self setPrimitiveValue:tmpOrderedSet forKey:@"<$Relationship.name$>"]; + [self didChange:NSKeyValueChangeInsertion valuesAtIndexes:indexes forKey:@"<$Relationship.name$>"]; } - (void)removeObjectFrom<$Relationship.name.initialCapitalString$>AtIndex:(NSUInteger)idx { - [self.<$Relationship.name$>Set removeObjectAtIndex:idx]; + NSIndexSet* indexes = [NSIndexSet indexSetWithIndex:idx]; + [self willChange:NSKeyValueChangeRemoval valuesAtIndexes:indexes forKey:@"<$Relationship.name$>"]; + NSMutableOrderedSet *tmpOrderedSet = [NSMutableOrderedSet orderedSetWithOrderedSet:[self <$Relationship.name$>]]; + [tmpOrderedSet removeObjectAtIndex:idx]; + [self setPrimitiveValue:tmpOrderedSet forKey:@"<$Relationship.name$>"]; + [self didChange:NSKeyValueChangeRemoval valuesAtIndexes:indexes forKey:@"<$Relationship.name$>"]; } - (void)insert<$Relationship.name.initialCapitalString$>:(NSArray *)value atIndexes:(NSIndexSet *)indexes { - [self.<$Relationship.name$>Set insertObjects:value atIndexes:indexes]; + [self willChange:NSKeyValueChangeInsertion valuesAtIndexes:indexes forKey:@"<$Relationship.name$>"]; + NSMutableOrderedSet *tmpOrderedSet = [NSMutableOrderedSet orderedSetWithOrderedSet:[self <$Relationship.name$>]]; + [tmpOrderedSet insertObjects:value atIndexes:indexes]; + [self setPrimitiveValue:tmpOrderedSet forKey:@"<$Relationship.name$>"]; + [self didChange:NSKeyValueChangeInsertion valuesAtIndexes:indexes forKey:@"<$Relationship.name$>"]; } - (void)remove<$Relationship.name.initialCapitalString$>AtIndexes:(NSIndexSet *)indexes { - [self.<$Relationship.name$>Set removeObjectsAtIndexes:indexes]; + [self willChange:NSKeyValueChangeRemoval valuesAtIndexes:indexes forKey:@"<$Relationship.name$>"]; + NSMutableOrderedSet *tmpOrderedSet = [NSMutableOrderedSet orderedSetWithOrderedSet:[self <$Relationship.name$>]]; + [tmpOrderedSet removeObjectsAtIndexes:indexes]; + [self setPrimitiveValue:tmpOrderedSet forKey:@"<$Relationship.name$>"]; + [self didChange:NSKeyValueChangeRemoval valuesAtIndexes:indexes forKey:@"<$Relationship.name$>"]; } - (void)replaceObjectIn<$Relationship.name.initialCapitalString$>AtIndex:(NSUInteger)idx withObject:(<$Relationship.immutableCollectionClassName$>*)value { - [self.<$Relationship.name$>Set replaceObjectAtIndex:idx withObject:value]; + NSIndexSet* indexes = [NSIndexSet indexSetWithIndex:idx]; + [self willChange:NSKeyValueChangeReplacement valuesAtIndexes:indexes forKey:@"<$Relationship.name$>"]; + NSMutableOrderedSet *tmpOrderedSet = [NSMutableOrderedSet orderedSetWithOrderedSet:[self <$Relationship.name$>]]; + [tmpOrderedSet replaceObjectAtIndex:idx withObject:value]; + [self setPrimitiveValue:tmpOrderedSet forKey:@"<$Relationship.name$>"]; + [self didChange:NSKeyValueChangeReplacement valuesAtIndexes:indexes forKey:@"<$Relationship.name$>"]; } - (void)replace<$Relationship.name.initialCapitalString$>AtIndexes:(NSIndexSet *)indexes with<$Relationship.name.initialCapitalString$>:(NSArray *)value { - [self.<$Relationship.name$>Set replaceObjectsAtIndexes:indexes withObjects:value]; + [self willChange:NSKeyValueChangeReplacement valuesAtIndexes:indexes forKey:@"<$Relationship.name$>"]; + NSMutableOrderedSet *tmpOrderedSet = [NSMutableOrderedSet orderedSetWithOrderedSet:[self <$Relationship.name$>]]; + [tmpOrderedSet replaceObjectsAtIndexes:indexes withObjects:value]; + [self setPrimitiveValue:tmpOrderedSet forKey:@"<$Relationship.name$>"]; + [self didChange:NSKeyValueChangeReplacement valuesAtIndexes:indexes forKey:@"<$Relationship.name$>"]; } @end <$endif$><$endif$><$endforeach do$>