[我试图在更新参考列表并在此代码块的第一行得到错误之后,将其保存回CloudKit。
错误:对成员'save(_:completionHandler :)的引用不明确]
CKContainer.default().publicCloudDatabase.save(establishment) { [unowned self] record, error in
DispatchQueue.main.async {
if let error = error {
print("error handling to come")
} else {
print("success")
}
}
}
这位于用户要遵循给定位置(机构)的功能内。我们将获取现有的场所及其关注者记录,检查是否有选定的用户在其中,如果不存在则将其添加到列表中(如果关注者列表为null则创建它)。
Edit, in case helpful
//Both of these are passed in from the prior view controller
var establishment: Establishment?
var loggedInUserID: String?
@objc func addTapped() {
// in here, we want to take the logged in user's ID and append it to the list of people that want to follow this establishment
// which is a CK Record Reference
let userID = CKRecord.ID(recordName: loggedInUserID!)
var establishmentTemp: Establishment? = establishment
var followers: [CKRecord.Reference]? = establishmentTemp?.followers
let reference = CKRecord.Reference(recordID: userID, action: CKRecord_Reference_Action.none)
if followers != nil {
if !followers!.contains(reference) {
establishmentTemp?.followers?.append(reference)
}
} else {
followers = [reference]
establishmentTemp?.followers = followers
establishment = establishmentTemp
}
[这是粘贴在问题顶部的CKContainer.default ..... save块的出现位置]
我已经浏览了有关“模棱两可的参考文献”的各种文章,但无法找出问题的根源。试图明确设置establisthmentTemp和关注者的类型,以防出现问题(基于其他相关职位的解决方案),但没有运气。害怕我是一个相对缺乏经验的新手的想法!
感谢帮助。
记录我想出的解决方案:
两个问题的组合:
((我认为第二点是“含糊提及成员”的原因错误)
我通过以下方式替换了保存尝试(问题中的第一段代码):
//first get the record ID for the current establishment that is to be updated
let establishmentRecordID = establishment?.id
//then fetch the item from CK
CKContainer.default().publicCloudDatabase.fetch(withRecordID: establishmentRecordID!) { updatedRecord, error in
if let error = error {
print("error handling to come")
} else {
//then update the 'people' array with the revised one
updatedRecord!.setObject(followers as __CKRecordObjCValue?, forKey: "people")
//then save it
CKContainer.default().publicCloudDatabase.save(updatedRecord!) { savedRecord, error in
}
}
}