mentrena / SyncKit

Automatic CloudKit synchronization
https://mentrena.github.io/SyncKit/
MIT License
507 stars 59 forks source link

Fatal Error in recordToUpload method #106

Closed dstranz closed 4 years ago

dstranz commented 5 years ago

We are experiencing a crash in recordToUpload method when originalObject is nil.

Zrzut ekranu 2019-11-7 o 10 23 58

I'm not sure if such record should be totally ignored during sync or deleted from iCloud?

mentrena commented 5 years ago

It probably should be ignored, but I'd like to understand why this happens. By any chance do you know how easy to reproduce this is? Was the object deleted halfway through a sync?

dstranz commented 5 years ago

I'm trying to reproduce it on my device, but yes, it was related to some remove / insert CD objects operations.

dstranz commented 5 years ago

OK, I'm able to reproduce it. I have 2 Core Data entities A and B with relation A(1) to B(N).

  1. I have object A with (let's say) uniqueId=A1 and B with uniqueId=B1.
  2. Then I'm removing B1
  3. ...and adding new object with uniqueId=B1 and related to A1

When I'm doing that several times and restart app CloudKit crashes.

mentrena commented 5 years ago

Is that happening halfway through the synchronisation?

dstranz commented 5 years ago

It's crashing when I'm calling synchronize() in AppDelegate during launch.

mentrena commented 5 years ago

Ok, my first instinct would be to recommend using fully unique identifiers, since B1 and B1' are not really the same object. You could use UDIDs and still keep a property with your own different identifier, so even if they're different objects to CloudKit they can still be considered the same by your app.

dstranz commented 5 years ago

@mentrena Yes, after further tests it's definitely related to reusing the same uniqueId.

mentrena commented 4 years ago

Cool, I'm closing the issue, feel free to reopen or get in touch if you have more questions about this.