Post

Replies

Boosts

Views

Activity

CloudKit and SwiftData not syncing on MacOS
I have a simple app that uses SwiftUI and SwiftData to maintain a database. The app runs on multiple iPhones and iPads and correctly synchronises across those platforms. So I am correct setting Background Modes and Remote Notifications. I have also correctly setup my Model Configuration and ModelContainer (Otherwise I would expect syncing to fail completely). The problem arises when I run on a Mac (M1 or M3) either using Mac Designed for iPad or Mac Catalyst. This can be debugging in Xcode or running the built app. Then the app does not reflect changes made in the iPhone or iPad apps unless I follow a specific sequence. Leave the app, (e.g click on a Finder window), then come back to the app (i.e click on the app again). Now the app will show the changes made on the iPhone/iPad. It looks like the app on the Mac is not processing remote notifications when in the background - it only performs them when the app has just become active. It also looks like the Mac is not performing these sync operations when the app is active. I have tried waiting 30 minutes and still the sync doesn't happen unless I leave the app and come back to it. I am using the same development CloudKit container in all cases
2
4
406
Jul ’24
Name clashes with SwiftData classes
I have a shopping list app and the data model is very simple, just 5 entities. These have names List, Product, Item, Section and Data. For CoreData I was able to use the auto-generated classes and gave my own names for the classes (prefixing my entity names with CD - e.g CDList) However with SwiftData I don't have that capability. My @Model classes are named List, Data etc and obviously these clash with the standard Swift/SwiftUI classes. Even the much quoted example app has the same issue a task todo list with an entity named Task, which would clash with Swift's own Task class. Is the correct/only approach that I don't use the @Model macro but roll my own SwiftData classes - e.g inline the macros, or is there a way I can give the @Model classes my own name (e.g SDList, and leave the CoreData entity names as they are). I don't really want to rename my entities if at all avoidable.
2
1
657
Dec ’23