我使用以下代码从CloudKit查询。但是,我得到了:
第“在打开可选值时意外发现nil”
publicDatabase!.perform
行上的错误:
print((currentuserID?.recordName)!)
let predicate = NSPredicate(format: "createdBy == %@", (currentuserID?.recordName)!)
let query = CKQuery(recordType: "Amigos", predicate: predicate)
print("Query record creators = to current user id")
publicDatabase!.perform(query, inZoneWith: nil, completionHandler: ({results, error in
if (error != nil) {
DispatchQueue.main.async {
//self.notifyUser("Cloud Access Error",
//message: error.localizedDescription)
print("QUERY FAILED")
}
} else {
if results!.count > 0 {
print(results!.count)
var record = results![0]
print(record)
DispatchQueue.main.async {
print("moving user to updateLoc")
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "updateLocation")
self.present(vc, animated: true, completion: nil)
}
} else {
DispatchQueue.main.async {
//self.notifyUser("No Match Found",
//message: "No record matching the address was found")
print("no user currently")
print("moving user to sign up page")
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "signUp")
self.present(vc, animated: true, completion: nil)
}
}
}
}))
有谁知道为什么会这样?