Post

Replies

Boosts

Views

Activity

Reply to SwiftData crashes after updating to MacOS 15.2
Apologies for the delay. It took me some digging, but I have resolved the issue. In the end it had nothing to do with SwiftData, but rather with Actors and illegally crossing actor boundaries. I have a singleton that holds a reference to my main SwiftData Container, that I can access using SwiftDataCoordinator.shared.container This shared instance lives on the MainActor. My issue arose because I was instantiating my ModelActors like this: Task.detached { let modelActor = SortableDataService(modelContainer: SwiftDataCoordinator.shared.container) etc... The fix was to do this: let container = SwiftDataCoordinator.shared.container Task.detached { let modelActor = SortableDataService(modelContainer: container) etc... In the end quite obvious, but it took me a while to see it. Leaving this here in case others run into this.
Jan ’25
Reply to modelContext.save triggers warning: publishing changes from background threads is not allowed
Thanks! Elsewhere in my code I am observing a didSave notification: .onReceive(NotificationCenter.default.publisher(for: ModelContext.didSave)) { object in ... So this call is triggering that warning, and it is telling me that whoever is observing didSave will not get notifications from that specific call, since it is running on a background thread. I think I get it :)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’24