0

I just started using an NSOrderedSet with Core Data, and the first object I try to add, it fails. I found this post describing the failure: Exception thrown in NSOrderedSet generated accessors

Now I want to remove an object at a specific index. I get unrecognized selector sent to instance when I call the generated Core Data method. For me it looks like:

removeObjectFromAddressAnnotationsAtIndex:

I was wondering if I'm doing something wrong, or if there is also a bug for this generated method as well. When I stepped through, I saw my index did line up with what I expected so I'm not sure what it is.

Edit:

I use it like so:

[_route removeAddressAnnotationsAtIndexes:[NSIndexSet indexSetWithIndex:indexToRemove]];
[_route removeObjectFromAddressAnnotationsAtIndex:indexToRemove];

I've tried both, and both fail with this error:

[Route removeAddressAnnotationsAtIndexes:]: unrecognized selector sent to instance 0xea71980
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Route removeAddressAnnotationsAtIndexes:]: unrecognized selector sent to instance 0xea71980'
Community
  • 1
  • 1
Crystal
  • 25,222
  • 53
  • 203
  • 370
  • can you show the code you are using and the exact error? – Gabriele Petronella Sep 30 '13 at 03:14
  • @GabrielePetronella I added the code you requested. – Crystal Sep 30 '13 at 03:18
  • It doesn't look like the known bug in generated accessors, since `Route` doesn't appear to be responding to that selector. Are you sure that the method naming is correct and that the relationship is `to-many` in the core data model editor? – Gabriele Petronella Sep 30 '13 at 03:24
  • @GabrielePetronella Ya I just checked, it says M (to-many) for my Route entity. I also copied and pasted the method when I tried using it. I also am able to jump to the definition on those methods and I end up going to my Route.h file. But knowing that there is no known bug for this, then I'll just keep digging. Thanks! – Crystal Sep 30 '13 at 03:26
  • Try to override that method with your own implementation, place a breakpoint in it an see whether it gets called. – Gabriele Petronella Sep 30 '13 at 03:29
  • @GabrielePetronella Yes if I override it with my own implementation, it does get called. I copied and pasted the generated accessor from the .h to the .m and just added a log. My log does get to the console. – Crystal Sep 30 '13 at 03:33
  • So those methods are not being generated at all by Core Data. Weird. – Gabriele Petronella Sep 30 '13 at 05:23

1 Answers1

1

I have pretty much given up on NSOrderedSet. They are a bit unwieldy being neither derived from NSArray nor from NSSet, so a lot of the usual functionality is simply not available.

In my Core Data models, I have included a position or order attribute to keep track of the order. Simple and reliable.

Mundi
  • 77,414
  • 17
  • 110
  • 132