The following runtime warning is emitted by Xcode when using the manageSubscriptionsSheet with an ObservableObject:
\ContentViewModel.isPresented is isolated to the main actor. Accessing it via Binding from a different actor will cause undefined behaviors, and potential data races; This warning will become a runtime crash in a future version of SwiftUI. Publishing changes from background threads is not allowed; make sure to publish values from the main thread (via operators like receive(on:)) on model updates.
This minimal sample project reproduces the issue:
class ContentViewModel: ObservableObject { @Published var isPresented = false func didTapButton() { self.isPresented = true } } struct ContentView: View { @ObservedObject var viewModel: ContentViewModel var body: some View { Button("Tap me") { self.viewModel.didTapButton() } .manageSubscriptionsSheet(isPresented: self.$viewModel.isPresented) } }
Reproduced on:
- Xcode 16.2
- Xcode 16.3 beta
both with a simulator and a real device.
This doesn't happen when using @Observable
.