SwiftData and CloudKit

Recently I've been working on a demo project called iLibrary. The main goal was to learn more about CloudKit and SwiftData. After a while I noticed that there were some hangs/freezes when running the app in debug mode.

I first tried this with Xcode 15.4 and iOS 17.5. Here the hang only appears at the beginning, but only for a few seconds. But when I exit debug mode, there are no more hangs.

With Xcode 16 beta 4 and iOS 18 it looks completely different. In this case, the hangs and freezes are always present, whether in debug mode or not. And it's not just at the beginning, it's throughout the app. I'm aware that this is still a beta, but I still find this weird. And when I profile this I see that the main thread gets quite overloaded. Interestingly, my app doesn't have that many operations going on. So I guess something with the sync of SwiftData or my CloudKitManger where I fetch some records from the public database is not running fine.

Lastly, I wanted to delete the iCloud app data. So I went to Settings and tried to delete it, but it didn't work. Is this normal?

Does anyone have any idea what this could be? Or has anyone encountered this problem as well? I'd appreciate any support.

My project: https://github.com/romanindermuehle/iLibrary

Also finding hangs on main thread (100%) which depend on where and how the app is launched. Does not seem to be app code issue.

Experiencing the same thing. Any iCloud sync operation following an insert or modification of SwiftData objects freeze the UI. It is infuriating.

I seem to be having a similar issue. My app would lag or glitch a bit if I scrolled down immediately after the app launched. I thought it was the way I was calculating some data and presenting it, but I realized that it stopped once CloudKit stopped outputting stuff to the console. If I wait for that to stop, it doesn't lag. If I disconnect my phone from a network, so it can't sync, it doesn't lag.

I am having the same issues with SwiftData and CloudKit:

  • My app freezes without throwing errors
  • I can't delete iCloud data

Additionally, I'm seeing weird behavior with local updates being reverted after about 10 seconds. I'm using an isDeleted bool to soft-delete photos from the UI, and they reappear after 10 seconds. I can see the isDeleted bool switching from 0 -> 1 -> 0 when inspecting the default SwiftData SQLite instance

SwiftData and CloudKit
 
 
Q