Search code examples
iosobjective-coopcore-datansset

How to design "ordering" of objects with Core Data


I have a Bullet object and a List object. A List has many bullets and a Bullet can belong to many Lists.

But I need to guarantee ordering of Bullet objects. For example, a List object should always have #1 Bullet A #2 Bullet B and #3 Bullet C in that order. Another List (List B) might have those same bullets, but in a different order, #1 Bullet B, #2 Bullet C and #3 Bullet A.

NSSet doesn't store ordering, and Core Data doesn't allow arrays.

What should I do? Can I do something with properties here?

Edits: After listening to the comments below, I realized that it's a "Many to Many" relationship between lists and bullets ... For example, a Bullet (name: "Egg") can appear in the List (name: "Dairy") and the List (name: "Food").


Solution

  • Use ordered relationship. It is mapped to NSOrderedSet.