Fetch data including CKReference from CloudKit

285 views Asked by At

I have been using CloudKit service for a long time, and thus storing a lot of data in there. Now, I have a second device connecting to CloudKit, and thus fetching all the data.

Say I have two record types Task and List, where Task has a CKReference pointing to List. Typically, when each record is processed, I will persist that to local cache. The actual scenario is more complicated with multiple relationships.

Question:

What happened if a Task record arrives, but its linked List record is not here yet?

Should I cache this record for later processing, or initiate a separate per record operation to pull that particular List first?

Any other suggestions?

1

There are 1 answers

0
Harry Ng On

I found the answer here in Apple Document.

Basically the suggestion is to fetch the missing records specifically (e.g. using CKFetchRecordsOperation), and then apply the updates to local cache.