我正在制作一个应用程序,用于存储每个用户的评论,然后将其显示在我的应用程序中。 (就像餐馆评分应用一样)但是,当用户输入评论并点击“提交”时,仪表板上似乎什么也没有。
每种记录类型都设置为可查询,但是当我单击查询结果时,它给了我应该将索引设置为可查询的错误。
这是我的代码。(迅速)
@IBAction func OnSubmitTouched(_ sender: UIButton) {
if (textField.text != ""){
let newComment = CKRecord(recordType: "Comment")
let publicDB = CKContainer.default().publicCloudDatabase
newComment.setValue(textField.text!, forKey: "comment")
CKContainer.default().fetchUserRecordID { recordID, error in
guard let recordID = recordID, error == nil else {
// error handling magic
return
}
//let userID = CKContainer fetchUserRecordIDWithCompletionHandler:
publicDB.save(newComment){
rec ,err in
if let error = err {
print(err.debugDescription)
return
}
publicDB.fetch(withRecordID: recordID) { record, error in
guard let record = record, error == nil else {
// show off your error handling skills
print(rec!["comment"]!)
return
}
print("The user record is: \(record)")
}
}
}
let predicate = NSPredicate(value: true)
let query = CKQuery(recordType: "Comment", predicate: predicate)
let operation = CKQueryOperation(query: query)
var commentRecords: [CKRecord] = []
operation.recordFetchedBlock = { record in
commentRecords.append(record)
}
operation.queryCompletionBlock = { cursor, error in
print(commentRecords)
}
CKContainer.default().publicCloudDatabase.add(operation)
答案 0 :(得分:0)
嗯... CloudKit非常适合告诉您保存失败的时间。您的任何错误都返回了什么吗?
此外,CKContainer.default()
是否返回与您在仪表板中查看的相同的容器ID?
我要检查的最后一件事是,您是否在iOS设备和CloudKit仪表板上使用了相同的Apple ID,以便查看同一用户的数据?