What's the best way to model ordered lists of items with core data?
views:
187answers:
1
+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
2009-05-04 03:40:14
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
2009-05-04 11:47:41