If I understand your use case correctly, you can make movieRecord.recordID.recordName the name of the movie and use CKModifyRecordsOperation with savePolicy IfServerRecordUnchanged to save efficiently if it does not exist. Then it will return an error that can be ignored if you try to save a record that already exists on the server:
let saveRecordsOperation = CKModifyRecordsOperation() saveRecordsOperation.recordsToSave = [movieRecord] saveRecordsOperation.savePolicy = .IfServerRecordUnchanged
Using savePolicy IfServerRecordUnchanged this operation will save the new video if it does not already exist on the server ("Save if it doesn’t exist"), but will return an error below if you try to overwrite a movie record that already exists on the server (provided that it not a new modified version of the record received from the server):
<CKError 0x14d23980: "Server Record Changed" (14/2017); server message = "record to insert already exists">
You can handle this conflict in perRecordCompletionBlock , but in your specific use case you can just do nothing with the conflict error, so each movie entry will be the first record saved with this CKRecordID.
source share