CloudKit: Fetch all records with a certain record type?

后端 未结 6 810
鱼传尺愫
鱼传尺愫 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:18

    Solution for Swift 4, shows how to fetch all the records of type "YourTable", also prints System Field and Custom Field:

    let query = CKQuery(recordType: "YourTable", predicate: NSPredicate(value: true))
    CKContainer.default().publicCloudDatabase.perform(query, inZoneWith: nil) { (records, error) in
      records?.forEach({ (record) in
    
        // System Field from property
        let recordName_fromProperty = record.recordID.recordName
        print("System Field, recordName: \(recordName_fromProperty)")
    
        // Custom Field from key path (eg: deeplink)
        let deeplink = record.value(forKey: "deeplink")
        print("Custom Field, deeplink: \(deeplink ?? "")")
      })
    }
    

提交回复
热议问题