我目前正在使用最新的 Kinvey SDK(版本 3.3.5)将 swift 2.3 迁移到 3。自 1x 版本以来,他们已经进行了大量更新。我的问题是有人能够成功查询 PersistableKeyID 字段并提取多个对象吗?
我过去能够使用“loadObjects”函数,该函数将字符串数组作为参数。此函数已被弃用并被 find(byId) 取代。见下文:
dataStore.find(byId: "only takes one") { uClass, error in
if let uClass = uClass {
//succeed
print("UClass: \(uClass)")
} else {
//fail
}
问题是,它只接受单个字符串作为参数。我尝试使用查询功能,但无法让它将“_id”字段作为参数。使用以下代码:
//Just statically creating the sectionID array for now. This will dynamically be created
testIDs = ["58668307206c11177e5ab0d4", "58668307206c11177e5ab0d4", "57ad00a505a2bb55632659c3"]
let sectionStore = DataStore<Section>.collection()
let sectionQuery = Query(format: "_id IN %@", testIDs)
sectionStore.find(sectionQuery) {sectionResult, error in
if let sectionResult = sectionResult {
self.sectionsTest = sectionResult
self.sectionCollectionView.reloadData()
} else{
//Error
}
}
我收到错误:
'Invalid property name', reason: 'Property '_id' not found in object of type 'Section'
既然“loadObjects”已经被贬值,有人知道如何执行此操作吗?我找不到传递的“find(byIds)”。
最佳答案
Jbone107,
我能够通过此获得结果,请告诉我以下内容是否适合您。
let id:[String] = ["5855026650a816ec29012908","5855024a21400c5b492bea20"]
let query = Query(format: "_id IN %@", id)
dataStore.find(query) { data, error in
if let data = data {
//succeed
print(“Data: \(data)")
} else {
//fail
print("fetching failed")
}
}
谢谢, 普拉纳夫, 金维
关于ios - Kinvey 3.3.5 SDK 按 ID 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41352834/