Can I add a CKDatabaseOperation to the queue belonging to a CKContainer object using CKContainer.add(_:)?

Can I add a CKDatabaseOperation to the queue belonging to a CKContainer object using CKContainer.add(_:)?

The CKContainer.add(_:) method takes a CKOperation argument, so it will take a subclass of CKOperation as far as I can tell. I can't find any documentation on this.

What I'm trying to figure out is which queue should I add a CKFetchRecordsOperation object to? Should I use CKDatabase.add(:), or CKContainer.add(:)?

let fetchRecordsOperation = CKFetchRecordsOperation.fetchCurrentUserRecordOperation()

I need the CKRecord for the current user for the entire CKContainer, or for the privateCloudDatabase and the sharedCloudDatabase to be specific. If I pass the CKFetchRecordsOperation object to the queue for CKDatabase, would that not return the current CKRecord for the current user for that CKDatabase only?

I suspect that if there is a separate CKRecord representing the current user in each database in a container, that they would each hold identical values, even identical recordName fields. Is that the case?

Concept

  • Assume user A uses the app and CKFetchRecordsOperation.fetchCurrentUserRecordOperation gets executed, user A's record would be returned.

  • User is a system defined record type

  • User A will have access to the following:

    • Public database
    • Private database (if authenticated)
    • Shared database (if authenticated)
  • User B will have his / her own private and shared database.

  • Only user can be logged on to one device at a given time, you can't have 2 iCloud accounts signed on the device (In Settings)

  • So you can only get one record for the current user.

Reference:

https://developer.apple.com/icloud/cloudkit/designing/

Queue to use

  • For CKFetchRecordsOperation is a subclass of CKDatabaseOperation so you need to use CKDatabase.add
  • If you use CKContainer.add an exception will be thrown *** Terminating app due to uncaught exception 'CKException', reason: 'CKDatabaseOperations must be submitted to a CKDatabase'
Can I add a CKDatabaseOperation to the queue belonging to a CKContainer object using CKContainer.add(_:)?
 
 
Q