Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何通过CKModifyRecordsOperation更新CKRecord?_Ios_Swift_Icloud_Cloudkit_Ckmodifyrecordsoperation - Fatal编程技术网

Ios 如何通过CKModifyRecordsOperation更新CKRecord?

Ios 如何通过CKModifyRecordsOperation更新CKRecord?,ios,swift,icloud,cloudkit,ckmodifyrecordsoperation,Ios,Swift,Icloud,Cloudkit,Ckmodifyrecordsoperation,我知道用ID更新CKRecord只是使用fetchRecordWithID和使用ckmodifyrecords操作,如下所示 publicData.fetchRecordWithID(recordIDToSave) { (record, error) in if let recordToSave = record { //Modify the record value here recordToSave.setObject("value", forKey: "key")

我知道用ID更新CKRecord只是使用fetchRecordWithID和使用ckmodifyrecords操作,如下所示

publicData.fetchRecordWithID(recordIDToSave) { (record, error) in

if let recordToSave =  record {

    //Modify the record value here
    recordToSave.setObject("value", forKey: "key")

    let modifyRecords = CKModifyRecordsOperation(recordsToSave:[recordToSave], recordIDsToDelete: nil)
    modifyRecords.savePolicy = CKRecordSavePolicy.AllKeys
    modifyRecords.qualityOfService = NSQualityOfService.UserInitiated
    modifyRecords.modifyRecordsCompletionBlock = { savedRecords, deletedRecordIDs, error in
        if error == nil {
            print("Modified")
        }else {
            print(error)
        }
    }
        publicData.addOperation(modifyRecords)
    } else {
        print(error.debugDescription)
    }
}
但是我可以在不使用fetchRecord的情况下更新记录吗?

我找到了解决方案

只需将CKModifyRecordsOperation操作的保存策略设置为changedKeys