Search code examples
iosicloudcloudkit

Can I save an object graph to CloudKit?


I have a model A with a reference list to model B.

Is there any way to save A filled with B aside from creating A, creating each B element in the list one at a time, and then saving the reference list?

Even in the trivial case of a single association the saving is complex and not atomic.


Solution

  • You do have to save record A first because you need the recordId for setting the CKReference fields for all the B records. Then you can save all the B records in one operation by using the CKModifyRecordsOperation which has support for saving multiple items in one action.