Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

SwiftData and iCloud

I'm a first time developer for Swift, (getting on a bit!) but after programming in VB back in the late 90s I wanted to write an app for iPhone. I think I might have gone about it the wrong way, but I've got an app that works great on my iPhone or works great on my iPad. It saves the data persistently on device, but, no matter how much I try, what I read and even resorting to AI (ChatGPT & Gemini) I still can't get it to save the data on iCloud to synchronise between the two and work across the devices. I think it must be something pretty fundamental I'm doing (or more likely not doing) that is causing the issue.

I'm setting up my signing and capabilities as per the available instructions but I always get a fatal error. I think it might be something to do with making fields optional, but at this point I'm second guessing myself and feeling a complete failure. Any advice or pointers would be really gratefully appreciated. I like my app and would like eventually to get it on the App Store but at this point in time I feel it should be on the failed projects heap!

I've even tried a new Xcode project for iOS and asking it to use SwiftData and CloudKit - the default project should work - right? But it absolutely doesn't for me. Please send help!!

Answered by DTS Engineer in 835371022

You might consider starting with the following post:

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

You might consider starting with the following post:

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

I eventually solved the problem. I had a relationship, just the one, that I hadn't marked as optional. My tip to anyone else who has a similar problem is to make sure you run the app on the simulator rather than just directly on your phone as the debug information will give you a much clearer idea of what is going wrong. I'm just a hobbyist writing my first app so whereas proper developers would have known this, I didn't have a clue! My app is looking fabulous now though :)

SwiftData and iCloud
 
 
Q