gpt4 book ai didi

ios - recordID 的值类型为引用,无法查询

转载 作者:可可西里 更新时间:2023-11-01 01:00:01 25 4
gpt4 key购买 nike

错误是:字段 '__recordID' 的值类型为引用,无法使用过滤器值类型字符串查询。

代码:

func getImage() {
let predicate = NSPredicate(format: "recordID = %@", myRecordID)
let query = CKQuery(recordType: "Images", predicate: predicate)
publicDB.performQuery(query, inZoneWithID: nil , completionHandler: ({ results, error in
if(error != nil) {
print("Error")
}
else {
if results!.count > 0 {
for record in results! {
print("I have results from query")
}
else {
print("query returned with no results")
}
}
}))

myRecordID 是:3F1CF4EC-95F4-4659-AA47-B00048B3BBAE 有效

最佳答案

就像错误告诉您的那样:您必须使用引用而不是字符串进行查询。

所以你的代码必须是:

let referenceField = "recordID"
let refId = CKRecordID(recordName: myRecordID)
let ref = CKReference(recordID: refId, action: CKReferenceAction.None)
let query = CKQuery(recordType: recordType, predicate: NSPredicate(format: "%K == %@", referenceField ,ref))

不过话又说回来了。使用以下内容更容易获得记录:

publicDB.fetchRecordWithID(CKRecordID(recordName: recordId), completionHandler: {record, error in

关于ios - recordID 的值类型为引用,无法查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35823314/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com