I've created two entities in core data model (Courier and Occupation in this example), and created an inverse relationship between them, which also caused a crush in xcode. After that, I've set the relationship as one courier to many occupations and created classes.
The occupation class was created empty, but courier class was populated with following code:
- (void)addOccupationsObject:(NSManagedObject *)value {
NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
[self willChangeValueForKey:@"occupations" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
[[self primitiveValueForKey:@"occupations"] addObject:value];
[self didChangeValueForKey:@"occupations" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
[changedObjects release];
}
- (void)removeOccupationsObject:(NSManagedObject *)value {
NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
[self willChangeValueForKey:@"occupations" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];
[[self primitiveValueForKey:@"occupations"] removeObject:value];
[self didChangeValueForKey:@"occupations" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];
[changedObjects release];
}
- (void)addOccupations:(NSSet *)value {
[self willChangeValueForKey:@"occupations" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value];
[[self primitiveValueForKey:@"occupations"] unionSet:value];
[self didChangeValueForKey:@"occupations" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value];
}
- (void)removeOccupations:(NSSet *)value {
[self willChangeValueForKey:@"occupations" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value];
[[self primitiveValueForKey:@"occupations"] minusSet:value];
[self didChangeValueForKey:@"occupations" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value];
}
I have two questions about it:
- What exactly does it do?
- Does it guarantee consistency of this model? (I know it should, but after the crash I'm not sure if xcode's logic in generating this code was correct).
- Why was occupation class created empty?