In building a note-taking app for meetings, I need to synchronise notes between devices, primarily between the iPad and iPhone. I was already using SwiftData for the models, and after some research, I found that it is relatively simple syncing SwiftData with iCloud. I should say that its simple to enable, but then you might run into some errors that you need to fix with your models and the classes or structs that use those models. This tutorial will cover what you need to know to get moving quickly.
Enabling iCloud support requires that you have a developer account. It is also best to test on actual devices rather than in the simulator. Before proceeding, check that signing is set to your development team account rather than the personal account you have. Assuming you already have a project to which you need to add iCloud support, follow along. If you are starting a new project, then ensure that you select SwiftData for storage and check the “Host in CloudKit” box.
To activate iCloud, in the Target, select + Capability.
Add iCloud and you’ll see the following added.
[Read more…]