Exception thrown in NSOrderedSet generated accessors

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

On my Lion app, I have this data model:

\"enter

The relationship subitem

相关标签:
25条回答
  • 2020-11-22 09:24

    I just got the problem in Swift (Xcode 6.1.1).

    The answer was DO NOT CODE ANY METHOD OR ADDITIONAL THINGS in your NSManagedObject subclasses. I think it is a compilator mistake. Very strange bug ..

    Hope it helps ..

    0 讨论(0)
  • 2020-11-22 09:24

    I'm quite sure it is finally fixed in iOS 10 beta 6!

    0 讨论(0)
  • 2020-11-22 09:25

    If you are using mogenerator, then instead of

    [parentObject add<Child>sObject:childObject];
    

    simply use:

    [[parent object <child>sSet] addObject:childObject];
    
    0 讨论(0)
  • 2020-11-22 09:30

    I agree that there may be 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.

    0 讨论(0)
  • 2020-11-22 09:30

    Yes, this is definitely a Core Data bug. I wrote up an ObjC-Runtime-based fix a while back, but at the time I figured it would be fixed soon. Anyway, no such luck, so I posted it up on GitHub as KCOrderedAccessorFix. Work around the problem on all your entities:

    [managedObjectModel kc_generateOrderedSetAccessors];
    

    One entity in particular:

    [managedObjectModel kc_generateOrderedSetAccessorsForEntity:entity];
    

    Or just for one relationship:

    [managedObjectModel kc_generateOrderedSetAccessorsForRelationship:relationship];
    
    0 讨论(0)
  • 2020-11-22 09:31

    The Apple docs To Many Relations says: you should access the proxy mutable set or ordered set using

    NSMutableOrderedSet * set = [managedObject mutableOrderedSetValueForKey:@"toManyRelation"];
    

    Modifying this set will add or remove relations to your managed object. Accessing the mutable ordered set using the accessor whether with [ ] or . notation is wrong and will fail.

    0 讨论(0)
提交回复
热议问题