PLEASE NOTE: This is not the same question as this question, as I already know that this stems from an Apple bug. Mind you, overriding the specific methods (say, -addFriendsObject:
if I had a friends relationship) is not an option, since I need to do this in a category so it works for any managed object and regardless of modifying the model and rebuildiong the autogenerated classes from it.
The need for this stems from the fact that apparently the minute one makes relationships ordered and to-many (NSMutableOrderedSets) Core Data dynamic methods go to hell:
- methods
-add<Relationship>Object
,-add<Relationship>
,-remove<Relationship>Object
and-remove<Relationship>
will all crash with an exception alike'NSInvalidArgumentException', reason: '*** -[NSSet intersectsSet:]: set argument is not an NSSet'
- methods along the lines of
insertObject:in<Relationship>AtIndex:
will instead crash because no implementation for them was actually provided by CoreData.
As far as 2, I wrote a category that overrides -methodSignatureForSelector:
and -forwardInvocation
to instead do something like mutableOrderedSetValueForKey
for the relationship name followed by the actual adding or removing.
Now for 1, the problem is that CoreData is actually providing implementations for those methods (though they are not the right implementations for ordered sets). So I need a way of intercepting those selectors too, so I can implement the behavior over mutableOrderedSetValueForKey.
Any ideas how to pull it off?