I have a CKRecord type “AccountInfo” which has a field “Wines” with is a list of references to “Wine” records. When I add a new wine, the wine record is added correctly and can reference its vineyard correctly but when I try and update the “AccountInfo” the “Wines” field stays the same.
Here’s the code:
//reference wine in user record
//Not working
let cloudDB = CKContainer.default().publicCloudDatabase
let userRecord = CKRecord(recordType: "AccountInfo", recordID: model.activeUser.recordID)
var wineRecords: [CKRecord.Reference] = []
for wine in model.activeUser.wines {
wineRecords.append(CKRecord.Reference(recordID: wine.recordID, action: .deleteSelf))
}
userRecord.setValuesForKeys([
"Wines": wineRecords as NSArray
])
let updateWinesList = CKModifyRecordsOperation(recordsToSave: [userRecord])
updateWinesList.savePolicy = .changedKeys
//save changes to users wine list
cloudDB.add(updateWinesList)
I’ve tried using CKModifyRecirdsOperation and saving the whole record with cloudDB.save but nothing has made any changes to the record. So can someone explain how to update a field of type Reference(List) in a CKRecord inside a Cloudkit database.




