Caleb Caleb - 1 year ago 99
iOS Question

Can't fetch userCKRecordID with Swift

I am getting the error: "Value of type 'CKDatabase' has no member 'fetchUserRecordIDWithCompletionHandler'." Was it taken out of the newest version of Xcode or swift 3?

func fetchUserRecords()
let publicDB = CKContainer.default().publicCloudDatabase
publicDB.fetchUserRecordIDWithCompletionHandler { (userID, error) -> Void in
if let userID = userID {
let reference = CKReference(recordID: userID, action: .None)
let predicate = NSPredicate(format: "creatorUserRecordID == %@", reference)
let query = CKQuery(recordType: "Location", predicate: predicate)
CKContainer.default().publicCloudDatabase.perform(query, inZoneWith: nil){
(records, error) in
if error != nil {
print("error fetching user records: \(error)")
completion(error as NSError?, nil)
} else {
print("found user records")
completion(nil, records)
guard let records = records else {
for record in records
//delete records

Answer Source

Swift 3 changes the names of lots of function calls. The new function signature is

func fetchUserRecordID(completionHandler: @escaping (CKRecordID?, Error?) -> Void)


rmaddy reports that the function is a function of CKContainer, not CKDatabase.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download