0

I have a NSOrderedSet relaitonship on an entity. The order of the objects is correct until I save, quit and relaunch the app. Then, when the entity is fetched, For some instances of the entity, the order of this relaitonship is different from what it was prior to the relaunch. It's as if the NSOrderedSet completely forgot the order.

Inspecting the model file shows that this property is indeed ordered:

    <relationship name="videoSegments" toMany="YES" deletionRule="Cascade" ordered="YES" destinationEntity="VideoSegment" inverseName="parentProject" inverseEntity="VideoSegment" syncable="YES"/>

I know about the autogenerated accessor code issue: Exception thrown in NSOrderedSet generated accessors however this is a different problem although it may be related somehow.

Community
  • 1
  • 1
Morrowless
  • 6,856
  • 11
  • 51
  • 81

2 Answers2

1

It doesn't forget anything, you should sort it. There is a difference between ordered and sorted.

Check NSMutableOrderedSet

some_id
  • 29,466
  • 62
  • 182
  • 304
0

If you need to return the data in a specific order, you need to add an attribute which defines the sort order, such as an index from 0..n, and sort the results on that.

CoreData doesn't pay any attention to the order in which you added the data

Russell
  • 5,436
  • 2
  • 19
  • 27