views:

187

answers:

1

What's the best way to model ordered lists of items with core data?

+6  A: 

As of OS X 10.6, there is no automatic way to maintain an ordered to-many relation in Core Data. You will have to add an "index" attribute to the target of the to-many relation and maintain this index manually or maintain a mapping from object ID to index in the entity that has the ordered to-many relationship. It's actually not that hard to implement the first of these options by overriding the KVC orderd to-many accessor and setter methods. You can also create a fetched property on the parent entity to make (read-only) access to the ordered list easier by adding a sort descriptor to the fetched property's fetch predicate.

Barry Wark
In the past I've used KVO in the parent entity to keep the order number up to date when object are added or removed.
Marc Charbonneau