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

macOS SwiftData app never syncs with CloudKit

I'm using SwiftData with CloutKit with a very simple app. Data syncs between iOS, iPadOS, and visionOS, but not macOS. From what I can tell, macOS is never getting CK messages unless I'm running the app from Xcode.

I can listen for the CK messages and show a line in a debug overlay. This works perfectly when I run from Xcode. I can see the notifications and see updates in my app. However, if I just launch the app outside of Xcode I will never see any changes or notifications. It is as if the Mac app never even tries to contact CloudKit.

Schema has been deployed in the CloudKit console. The app is based on the multi-platform Xcode template. Again, only the macOS version has this issue. Is there some extra permission or setting I need to set up in order to use CloudKit on macOS?

@State private var publisher = NotificationCenter.default.publisher(for: NSPersistentCloudKitContainer.eventChangedNotification).receive(on: DispatchQueue.main)
                .onReceive(publisher) { notification in
                    // Listen for changes in CK events
                    if let userInfo = notification.userInfo,
                       let event = userInfo[NSPersistentCloudKitContainer.eventNotificationUserInfoKey] as? NSPersistentCloudKitContainer.Event {
                        let message = "CloudKit Sync: \(event.type.rawValue) - \(event.succeeded ? "Success" : "Failed") - \(event.description)"

                        // Store for UI display
                        syncNotifications.append(message)
                        if syncNotifications.count > 10 {
                            syncNotifications.removeFirst()
                        }

                    }
                }
                .overlay(alignment: .topTrailing) {
                    if !syncNotifications.isEmpty {
                        VStack(alignment: .leading) {
                            ForEach(syncNotifications, id: \.self) { notification in
                                Text(notification)
                                    .padding(8)
                            }
                        }
                        .frame(width: 800, height: 500)
                        .cornerRadius(8)
                        .background(Color.secondary.opacity(0.2))
                        .padding()
                        .transition(.move(edge: .top))
                    }
                }

Fixed, in case anyone else runs into this:

Apparently, macOS builds don't include CloudKit by default, at least when starting from the multi-platform template project.

Here is an article that explains this a bit more. https://fatbobman.com/en/snippet/fix-synchronization-issues-for-macos-apps-using-core-dataswiftdata/

macOS SwiftData app never syncs with CloudKit
 
 
Q