踩进了 CoreData To-Many Ordered 问题的老坑

这已经是个老bug了,如果对多关系标成有序的,有些 Dynamically-Generated accessor Methods (add*) 会抛异常,还有一些干脆没生成。

我居然又中招了!去年已经中过的,没记性呀!这绝逼是个bug,有人老早做过补丁:https://github.com/CFKevinRef/KCOrderedAccessorFix

不过,这意思苹果的人是铁了心不修了,radar 上那个条目已经关闭了。

好在文档里提过的 -mutableOrderedSetValueForKey: 方法一直工作都很正常。唉,苹果准备花几年来更新文档呢? (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!

你可能感兴趣的:(踩进了 CoreData To-Many Ordered 问题的老坑)