Swift CloudKit SaveRecord “Error saving record”

后端 未结 3 1168
有刺的猬
有刺的猬 2021-01-30 18:52

I am trying to save a record to CloudKit but am getting an error. I had seen elsewhere that this was an issue that required knowing how to save but I can\'t get this to work.

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-30 19:36

    I had the same error, but I was already fetching the record by ID as Guto described. It turned out I was updating the same record multiple times, and things were getting out of sync.

    I have an update-and-save method that gets called by the main thread, sometimes rapidly.

    I'm using blocks and saving right away, but if you're updating records quickly you can arrive in a situation where the following happens:

    1. Fetch record, get instance A'.
    2. Fetch record, get instance A''.
    3. Update A' and save.
    4. Update A'' and save.

    Update of A'' will fail because the record has been updated on the server.

    I fixed this by ensuring that I wait to update the record if I'm in the midst updating it.

提交回复
热议问题