I'm currently designing a CloudKit
based syncing-solution and I wondered what the best way is to keep the order of a list (an array in my case) of cloud items (CKRecord
objects) consistent.
Apple advises against holding a reference to child objects and instead just reference the parent object with a CKReference
from the child. This works fine if you want to query your items based on one of it's properties (e.g. a creation date), but not if you have have an order which is determined by the user.
I've come up with two different approaches which are based on the same idea: maintain a manifest of identifiers to manage the item's position.
1) Sync an extra record (aka manifest) which has an array of identifiers, each identifying a CKRecord
object (and the corresponding local model object).
2) Create a parent object which holds an array of references (CKReference
objects) to it's child objects. This array maintains the given order.
I feel that this is not quite the best possible solution to this problem and I would be glad to hear what you think.