1

I had some trouble today with my first CoreData-steps and found this thread:
Exception thrown in NSOrderedSet generated accessors

Is there a fix for this I can load via cocoapods so that I don't have to do some silly workaround? I can't find one and implementing all accessors on my own I not what I use generators for :-)

Community
  • 1
  • 1
Sammy
  • 1,026
  • 1
  • 13
  • 26

2 Answers2

2

If you decide to give up and implement a (silly - i know) workaround (overriden generators), then this is the example of it:

- (void)addInvitesObject:(Invite *)value
{
    NSMutableOrderedSet* tempSet = [NSMutableOrderedSet orderedSetWithOrderedSet:self.invites];
    [tempSet addObject:value];
    self.invites = tempSet;
}

- (void)removeInvitesObject:(Invite *)value
{
    NSMutableOrderedSet* tempSet = [NSMutableOrderedSet orderedSetWithOrderedSet:self.invites];
    [tempSet removeObject:value];
    self.invites = tempSet;
}
damirstuhec
  • 5,451
  • 1
  • 19
  • 37
  • 2
    How does this differ from the answers given to the linked question, such as http://stackoverflow.com/a/7922993/1187415? – Martin R Feb 27 '14 at 20:56
1

There is no other workaround, as Apple has not fixed it yet.

Your options include:

  • over-writing the accessor for your ordered sets / relationships
  • NOT using ordered relationships if you don't have to (this isn't as odd as it sounds -- really ask yourself if stored order is important in your related graph)
  • Use mogenerator for your models, which gives handy accessors for all your attributes and relationships, including accessors for the objects and the primitive values, which in this case, can be what you need

For me, I can't imagine life w/o mogenerator. :-) Apple should really be shipping something like it.

greymouser
  • 2,774
  • 18
  • 22
  • Does mogenerator create accessors that work correctly with ordered relationships ? – Martin R Feb 27 '14 at 20:58
  • Effectively, yes. For e.g., I have a model that contains ordered `items`. I can write - `[self.itemsSet addObject:item];`. Mogenerator abstracts the changing model attributes & relationships (as you develop), leaving you to implement higher-level model specifics. Read up on it -- it definitely makes life easier. – greymouser Feb 27 '14 at 21:00
  • A good point is this 'stored in order'. A nice side-effect was accessing via index. But I belief, I cold workaround that in the guy. Thx so fa – Sammy Feb 27 '14 at 21:07