Replies: 1 comment 1 reply
-
Hi @darvelo, it is not correct to make changes to your model inside the trailing closure of
It is telling you that you are updating state at a time that it is not allowed to update state. All you can do in the Here is a plain, vanilla SwiftUI demo that demonstrates the same behavior: import SwiftUI
struct ContentView: View {
@State var isPresented = false
var body: some View {
Button("Tap") {
self.isPresented = true
}
.sheet(isPresented: self.$isPresented) {
let _ = self.isPresented = false
}
}
} Since this is not an issue with the library I am going to convert it to a discussion, and if you have more questions you can post there. |
Beta Was this translation helpful? Give feedback.
-
Description
I'm not sure if I'm doing something wrong with my code, but I get this runtime warning from SwiftUI when opening an alert or dialog:
I have an error handler in my VM which publishes an alert or dialog enum to the VM state, which is then read by SwiftUI. My problem was that the alert or dialog wouldn't be presented if a sheet was presented on top already, so I created a
ViewModifier
to reuse for both the main view and the sheet:When the event is published, it goes to both modifier instances, and I believe that's what triggers the warning from SwiftUI inside the
swiftui-navigation
library.FWIW I get a message in the console when not using
swiftui-navigation
, but it's not the same as this runtime warning:Though I'm not sure how best to handle this case where I need the alert or dialog to show even when a sheet is presented.
Checklist
main
branch of this package.Expected behavior
No SwiftUI warning at runtime.
Actual behavior
SwiftUI runtime warning from
Binding
extension.Steps to reproduce
Try out the reproducible example at https://github.com/darvelo/swiftui-runtime-error-sample
SwiftUI Navigation version information
0.7.2
Destination operating system
iOS 16
Xcode version information
14.3 (14E222b)
Swift Compiler version information
Beta Was this translation helpful? Give feedback.
All reactions