Search code examples
icloudcloudkit

Find out what database a CKRecord belongs to


How can (or, Can) I find out which iCloud database a CKRecord belongs to?

There should be four possiblities at this time:

  • private
  • public
  • shared
  • no database connection yet, if created on device

Solution

  • There is nothing in CKRecord that directly tells you what database it came from. But you always know the database from the source of the record.

    If you get a subscription notification or from fetching changes, you know the database from the CKQueryNotification, CKRecordZoneNotification, or the new CKDatabaseNotification.

    Of course if you are creating a new CKRecord, there is no database yet but you must know which database you intend to use (public, private, or the new shared).

    Certainly if you get a CKRecord from performing a query, you know which database was used for the query operation.

    If you need to persist a local copy of the record and then later you need to load that local copy and send it to the proper database, then your local copy must include data telling you which database it belongs to. Since you can always determine the source of a CKRecord when you obtain the record, this isn't an issue.