Force a CloudKit Error

I'm tracking down a CloudKit error of 'Failed to modify some records.'


How can I throw this error so that I can test my error handling code?


Is there a property of CKRecord I can set to force it to fail?


Code is currently something like:


var someRecords = [CKRecord]()
for i in (1...10) {
  let record = CKRecord(recordType: "Track", recordID: CKRecord.ID(zoneID: recordZone.zoneID))
  ...
  someRecords.append(record)
}

let operation = CKModifyRecordsOperation(recordsToSave: someRecords, recordIDsToDelete: nil)

operation.modifyRecordsCompletionBlock = { savedRecords, deletedRecords, error in
    DispatchQueue.main.async {
        if !self.handleError(error) { ... }
    }
}

Replies

You can deploy to production and then try to add new fields in some records.


You can set

modifyPublicRecords.savePolicy=CKRecordSaveIfServerRecordUnchanged;


and then change that fetch that record, change it and save it and then change it again and try to save it a second time. The second time will fail becuase the original was changed after the fetch.