CloudKit: Fetch all records with a certain record type?

后端 未结 6 838
鱼传尺愫
鱼传尺愫 2021-02-05 19:50

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         


        
6条回答
  •  说谎
    说谎 (楼主)
    2021-02-05 20:34

    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

提交回复
热议问题