I\'ve got two Entities that I\'ll call A and B. They are configured with To-Many relationships in both directions, so A.myBs and B.myAs are both NSSets.
Here is
I just had the same problem, which was why I saw this question. Maybe my solution will help some people in the same situation.
For me the answer was that in the NSManagedObject subclass I had over-riden:
- (void)willChangeValueForKey:(NSString *)inKey withSetMutation:(NSKeyValueSetMutationKind)inMutationKind usingObjects:(NSSet *)inObjects
- (void)didChangeValueForKey:(NSString *)inKey withSetMutation:(NSKeyValueSetMutationKind)inMutationKind usingObjects:(NSSet *)inObjects
This prevents the correct notifications being sent to the parent class (NSManagedObject) which handles the automatic reverse relationships.
If you're subclassing the Managed Object, shouldn't there be auto-generated to-many relationship methods? So that you would just need to call:
[aObject addBObject:bObject];
I found the error, if you are overriding any of these methods
// KVO change notification
- (void)willChangeValueForKey:(NSString *)key;
- (void)didChangeValueForKey:(NSString *)key;
- (void)willChangeValueForKey:(NSString *)inKey withSetMutation:(NSKeyValueSetMutationKind)inMutationKind usingObjects:(NSSet *)inObjects;
- (void)didChangeValueForKey:(NSString *)inKey withSetMutation:(NSKeyValueSetMutationKind)inMutationKind usingObjects:(NSSet *)inObjects;
it will cause NSManagedObject don't work well and the relationships won't be set correctly
Apple documentation: You must not override these methods.