Okay, so I created a new Xcode project using SwiftData, and ticked the box for iCloud integration. I added a container on the web dashboard. Then I added “ = Date()” to the definition of Item.timestamp so that it has a default value. I added the container to my Xcode project..
Then I added this “let config” and “let container” and changed the “.modelContainer” like this:
This will successfully add stuff to core data, which also appears in iCloud dashboard.
BUT, if I delete the app and re-launch, I don’t see the existing iCloud data until the SECOND launch, even though the Xcode runtime log shows it fetched it.
Do I need to do some magic to get it to refresh? Is the CloudKit subscription managed by SwiftData or do I need to do something for that?
thanks!
Per suggestion in Slack's "data-frameworks" WWDC 2023 channel, I submitted Feedback, as FB12245665.
@drewster Have you tried using SwiftData locally, i.e., no CloudKit container? When I do that, I lose all data between launches as the underlying
-wal
gets replaced when the ModelContainer is created.I don’t recall the exact differences offhand, but if you create a new project using SwiftData and without CloudKit, the setup is slightly different. I didn’t have any trouble with data persistence between runs.