According to Google Bard 🤖 this can happen if you are using an ObservableObject
@Published
property as the path: Binding
on a NavigationStack and you are changing the value of the property in the same frame.
⚠️ Something like this triggered the runtime warning for me, despite everything still working properly:
// ViewModel
class MyModelObject: ObservableObject {
@Published var path: [MyObject] = []
...
}
// View
@StateObject var model = MyModelObject()
var body: some View {
NavigationView(path: $model.path) {
...
✅ In the end, the following fixed the runtime warning, I had to make path:
read from a @State
property Binding
and still communicate to the view model using the onChange
function.
// ViewModel
class MyModelObject: ObservableObject {
@Published var path: [MyObject] = []
...
// Useful for manipulating a property observed by other components.
func update(_ path: [MyObject]) {
self.path = path
}
}
// View
@State var presentedPath: [MyObject] = []
@StateObject var model = MyModelObject()
var body: some View {
NavigationView(path: $presentedPath) {
...
}.onChange(of: presentedPath) { newPath in
model.update(path: newPath)
}
}