How to get default project with NSPersistentCloudKitContainer up and running?

To see the changes with Simulators you have to quit the app, and reload it (or build & run).

Simulators have never been able to receive Remote Notifications to trigger an iCloud sync so you need to manually force a sync, but I've found that syncing cannot be triggered manually from the menu in my Xcode 11 beta (gives an error).

There is a good post by Andrew Bancroft about some other things such as setting the automaticallyMergesChangesFromParent property to true, but this doesn't make a difference when using Simulators (EDIT: It does, but I didn't realise as I was just building & running each time).

Andrew's Post: https://www.andrewcbancroft.com/blog/ios-development/data-persistence/getting-started-with-nspersistentcloudkitcontainer/#where-s-my-data

I'm in the same boat as I can't afford to install any beta software (except Xcode) so I'm going to have to stick with the simulators. But my experience of converting an existing App to CloudKit has been very, very positive. I just had to do three things to my existing project:

  • Add Background Notification & CloudKit capabilities
  • Make sure all Core Data attributes & relationships are optional (or have a default value if nil)
  • Rename NSPersistentContainer to NSPersistentCloudKitContainer

...and that's it! Mind blown.

All my nested many-to-many relationships appear to work perfectly.

I still need to work out how to sync images currently stored as JPGs in the users Documents directory but I suspect they'll need to be stored in Core Data as BLOBs to enable conversion to CKAssets in the background.