I have an NSArrayController linked to a Core Data object, set to Auto Rearrange Content and filtered by a predicate. All is well until I try to nullify a relationship and assign another. At that point, my application crashes and I receive the following error:
Cannot remove an observer for the key path "career.type" from Object, most likely because the value for the key "career" has changed without an appropriate KVO notification being sent. Check the KVO-compliance of the Person class.
From snooping around, it appears that having my NSArrayController set to Auto Rearrange Content causes this issue. But I'm trying to resolve the problem without having to resort to manually rearranging the NSArrayController. Here's the pseudo-code that's triggering the error:
object.career = nil;
object.field = (Field *)item;
Here's the predicate my NSArrayController is using:
(career != NIL && career == %@) || (field != NIL && field == %@)
Where %@ for both instances is a CoreData object.
Basically, it looks as though the NSArrayController has an observer set for object.career.type and nullifying the relationship causes an issue when that observer is automatically removed. So I'm wondering if I'm going about this the wrong way? Should I be grabbing a copy of the object, deleting it from the MOC and reinserting it with career set to nil and field set accordingly?
How do I correctly notify the observer that type has been nullified? Note that all attributes and relationships mentioned here use vanilla KVO-compliant getters/setters.