I also had that problem, this is the solution: add @Bindable var viewModel = viewModel in your view’s body, even though I don’t think it is elegant.
@Observable
final class View1Model {
var text: String = ""
}
struct View1: View {
@State var viewModel = View1Model()
var body: some View {
View2()
.environment(viewModel)
}
}
struct View2: View {
@Environment(View1Model.self) var viewModel
var body: some View {
// use @Bindable to get the binding
@Bindable var viewModel = viewModel
TextField("Text", text: $viewModel.text)
}
}
Post
Replies
Boosts
Views
Activity
I have the same problem with my iPhone, but everything is ok on my iPad Pro, both are in the beta version OS, and in the same network. how strange!
I updated to iOS beta3 and Xcode15 beta3, the problem has solved.
on Xcode15 beta4, all workarounds above don’t work for me.
I notice that release notes mentioned that it is a known issue and recommend to run on device replacing preview, but it is not convenient.
is there any other workaround?
The solution is changing newLivingAccommodation.trip = trip to trip.livingAccommodation = newLivingAccommodation. After one year, Apple haven’t change this in their sample code.