Exception thrown in NSOrderedSet generated accessors

后端 未结 25 2538
天涯浪人
天涯浪人 2020-11-22 09:07

On my Lion app, I have this data model:

\"enter

The relationship subitem

25条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 09:18

    I agree that there maybe a bug here. I've modified the implementation of the add object >setter to append correctly to a NSMutableOrderedSet.

    - (void)addSubitemsObject:(SubItem *)value {
         NSMutableOrderedSet* tempSet = [NSMutableOrderedSet orderedSetWithOrderedSet:self.subitems];
         [tempSet addObject:value];
         self.subitems = tempSet;
    }
    

    Reassigning the set to self.subitems will ensure that the Will/DidChangeValue notifications >are sent.

    Leelll, are you sure that after such custom setup of NSMutableOrderedSet values stored in that set will be saved to the database correctly by CoreData? I didn't check that, but it looks like CoreData knows nothing about NSOrderedSet and expects NSSet as to-many relationship container.

提交回复
热议问题