Exception thrown in NSOrderedSet generated accessors

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

On my Lion app, I have this data model:

\"enter

The relationship subitem

25条回答
  •  难免孤独
    2020-11-22 09:34

    Received the same error, @LeeIII solution worked for me (thanks!). I suggest slightly modify it:

    • use objective-c category to store the new method (so we wont lose our method if Item is generated again)
    • check if we already have mutable set

    Content of Item+category.m:

    #import "Item+category.h"
    
    @implementation Item (category)
    
    - (void)addSubitemsObject:(SubItem *)value {
        if ([self.subitems isKindOfClass:[NSMutableOrderedSet class]]) {
            [(NSMutableOrderedSet *)self.subitems addObject:value];
        } else {
            NSMutableOrderedSet* tempSet = [NSMutableOrderedSet orderedSetWithOrderedSet:self.subitems];
            [tempSet addObject:value];
            self.subitems = tempSet;
        }
    }
    
    @end
    

提交回复
热议问题