8

I had a look through the existing documentation and couldn't find anything that confirms the behaviour I am seeing.

Starting on iOS 5, CoreData relationships can be ordered and in this case the returned object is a NSOrderedSet.

Can anyone confirm that the order of the objects in the set matches the order in which they have been created?

Cheers, Rog

Rog
  • 18,602
  • 6
  • 76
  • 97

2 Answers2

2

If you don't sort the order yourself using sortedArrayUsingComparator: then I believe the objects are sorted in the order in which they are added.

You can also manual set the order with with – insertObject:atIndex: .

https://developer.apple.com/library/mac/#documentation/Foundation/Reference/NSMutableOrderedSet_Class/Reference/Reference.html#//apple_ref/occ/cl/NSMutableOrderedSet

elprl
  • 1,940
  • 25
  • 36
1

You should create a NSMutabledOrderedSet with data from your old NSOrderedSet, make your changes and move your data back again:

NSMutableOrderedSet *orderedSet = [[NSMutableOrderedSet alloc] initWithSet:[self.myOrderedSet set]];
[orderedSet insertObject:newObject atIndex:index];
self.myOrderedSet = orderedSet;
monavari-lebrecht
  • 900
  • 3
  • 9
  • 23