Ответ 1
Вот код, который закончился для меня:
if let loadedData = defaults1.object(forKey: "locationData") as? Data {
let litt = NSKeyedUnarchiver.unarchiveObject(with: loadedData) as! CKRecord
let publicDB = CKContainer.default().publicCloudDatabase
publicDB.fetch(withRecordID: litt.recordID ,completionHandler: {
(record, error) in
if error == nil
{
publicDB.delete(withRecordID: (record?.recordID)!, completionHandler: {
(record, error) in
if(error == nil){
print("old record delete")
let id = self.locationRecord.recordID.recordName
self.locationRecord.setObject(locations, forKey: "location")
self.defaults1.set(id, forKey: "locationData")
self.updateLocationRecord(locations: locations)
}
else{
}
})
}else{
print("Error fetching previous record")
}
})
}
}
}