Update ordered ToMany relationship in CoreData

It is a well known bug, when a relationship is checked with ordered, some Dynamically-Generated accessor Methods (add*) will throw exception, some others (insert*) are just not generated.

I ran into this issue again. Yeah, I met it about 1 year ago. I’m one hundred percent sure it is a bug. And a patch is created by someone long ago https://github.com/CFKevinRef/KCOrderedAccessorFix

But, it seems Apple guys had decided not to fix it. The radar item are closed now!

Fortunately,  -mutableOrderedSetValueForKey: method mentioned by document always works. I guess it is the time for Apple to update their document (https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreData/Articles/cdUsingMOs.html#//apple_ref/doc/uid/TP40001803-SW3) :

Typically, however, you do not want to set an entire relationship, instead you want to add or remove a single element at a time. To do this, you should usemutableSetValueForKey: or one of the automatically-generated relationship mutator methods (see Dynamically-Generated Accessor Methods): unless it is order!

Leave a Reply

Your email address will not be published. Required fields are marked *