Problem

This question bothered me a lot when I first started to use CoreData + CloudKit.

The sync between local and cloud database worked perfectly while developing but as soon as the app was published to the AppStore, it stopped working.

Article

Here you can read my guide on how to use CoreData with SwiftUI.

Solution

Well the answer is pretty simple:

Your CloudKit scheme has to be deployed to production.

And every time you add or change your data models, you have to deploy it to production, so CloudKit knows what your data structure looks like and it will sync with CoreData.

Steps

  1. Go to the CloudKit console and then select CloudKit Database
  2. Select your container from the dropdown in the top-left corner
  3. Make sure your in the Development environment
  4. In the left sidebar, select Deploy Schema Changes…
  5. Verify the changes are correct
  6. Tap Deploy

You’re done!

Conclusion

This is a really simple step but it can be overlooked and it drove me crazy, trying to figuring out what was the problem.

I hope this will resolve your issue.

What are you thoughts about this? Tweet me @franceleonidev and share your opinion.

Source link