Why in this case when we tap the button and sheet comes in we go to the branch else even though we set title before isSheetPresented but it still somehow nil
Does it somehow related to under the hood stuff like View Tree and Render Tree?
and because CounterView’s body don’t capture title it cannot be stored in the Render Tree so it always would have the initial value of nil
If there are some well informed guys out here please help me figure this mystery out, I’d appreciate it!!!
struct ContentView: View {
@State private var title: String?
@State private var isSheetPresented: Bool = false
var body: some View {
Button("Hello, world!") {
title = "Sheet title"
isSheetPresented = true
}
.sheet(isPresented: $isSheetPresented, content: {
if let title {
Text(title)
} else {
EmptyView()
}
})
}
}