I have currently got CloudKit set up in my app so that I am adding a new record using the help of the following code below,
CKRecordID *recordID
In trying to fetch all records, and understand the structure and details of Cloudkit storage, I found it useful to have the following function available during debug. This uses semaphores to retain the data structure for printing. There may be a more elegant way to do this but this works!
//
// Print a list of records in all zones in all databases
//
func printRecordsInContainers() {
let myContainer = CKContainer.default()
// Edit the following dictionary to include any known containers and possible record types
let containerRecordTypes: [CKContainer: [String]] = [ myContainer: ["MyRecordType", "OldRecordType", "MyUser", "PrivateInfo"] ]
let containers = Array(containerRecordTypes.keys)
for containerz in containers {
let databases: [CKDatabase] = [containerz.publicCloudDatabase, containerz.privateCloudDatabase, containerz.sharedCloudDatabase]
for database in databases {
var dbType = ""
if database.databaseScope.rawValue == 1 { dbType = "Public" }
if database.databaseScope.rawValue == 2 { dbType = "Private" }
if database.databaseScope.rawValue == 3 { dbType = "Shared" }
//print("\(database.debugDescription)")
print("\n\n\n