2

I want to store the users preference in CloudKit attached to the users public User record. The preference can be either a private record or a shared record (shared by some other user).

Can I use CKReference to store a reference to the shared record, and if so how do I determine whether the stored CKReference is referring to the private or the public database ?

Currently if I store a CKReference to a private record then I am able to query the private database to retrieve the record but if I store a CKReference to the shared record then how can I determine which database to query.

Can I use a CKReference to link across databases or must I use something like record name to search for it and also store a separate reference to indicate whether it is a private or shared record ?

EDIT:

OK, it pays to read the documentation but it took a while to find the explanation I needed, here is the excerpt from the docs

You might also use record IDs is when you cannot use a CKReference object to refer to a record. References are only valid within a single zone of a database. To refer to objects outside of the current zone or database, save the strings in the record’s CKRecordID and CKRecordZoneID objects. When you want to retrieve the record later, use those strings to recreate the record and zone ID objects so that you can fetch the record.

https://developer.apple.com/documentation/cloudkit/ckrecordid

Duncan Groenewald
  • 8,496
  • 6
  • 41
  • 76
  • Thanks a lot, ran into the same problem. It might help if you add your own answer, because as a oversight people might think there is no solution to it. You can answer your own question – user1046037 Mar 26 '18 at 09:23
  • Done... I think at the time not enough time had elapsed to allow me to post my own answer and I forgot about it. – Duncan Groenewald Apr 04 '18 at 01:16

1 Answers1

3

OK, it pays to read the documentation but it took a while to find the explanation I needed, here is the excerpt from the docs

You might also use record IDs is when you cannot use a CKReference object to refer to a record. References are only valid within a single zone of a database. To refer to objects outside of the current zone or database, save the strings in the record’s CKRecordID and CKRecordZoneID objects. When you want to retrieve the record later, use those strings to recreate the record and zone ID objects so that you can fetch the record.

https://developer.apple.com/documentation/cloudkit/ckrecordid

Duncan Groenewald
  • 8,496
  • 6
  • 41
  • 76
  • Thanks a lot !!, I have a question about localizedDescription of CKError, could you help me with it. https://stackoverflow.com/questions/49856270/ckerror-localizeddescription – user1046037 Apr 17 '18 at 04:16