Curious if anyone can explain to me why, after tapping the words "Sheet 4," the screen returns to "Sheet 1" rather than "Foundation":
struct ContentView: View {
@State private var showSheet1: Bool = false
@State private var showSheet2: Bool = false
@State private var showSheet3: Bool = false
@State private var showSheet4: Bool = false
var body: some View {
Button(action: {
showSheet1.toggle()
}) {
Text("Foundation") // Click this phrase so that Sheet1=T, Sheet2=F, Sheet3=F, Sheet4=F
}
.sheet(isPresented: $showSheet1) { // Because Sheet1 is T...
Button(action: {
showSheet2.toggle()
}) {
Text("Sheet 1") // ...this appears. Click this phrase so that Sheet1=T, Sheet2=T, Sheet3=F, Sheet4=F
}
.sheet(isPresented: $showSheet2) { // Because Sheet2 is T...
Button(action: {
showSheet3.toggle()
}) {
Text("Sheet 2") // ...this appears. Click this phrase so that Sheet1=T, Sheet2=T, Sheet3=T, Sheet4=F
}
.sheet(isPresented: $showSheet3) { // Because Sheet3 is T...
Button(action: {
showSheet4.toggle()
}) {
Text("Sheet 3") // ...this appears. Click this phrase so that Sheet1=T, Sheet2=T, Sheet3=T, Sheet4=T
}
.sheet(isPresented: $showSheet4) { // Because Sheet4 is T...
Button(action: {
showSheet4.toggle()
showSheet3.toggle()
showSheet2.toggle()
showSheet1.toggle()
}) {
Text("Sheet 4") // ...this appears. Click this phrase so that Sheet1=F, Sheet2=F, Sheet3=F, Sheet4=F
}
}
}
}
}
}
}
As the View is reloaded each time the text is tapped, doesn't Swift start over from the var body: some View
each time, examine the values of the four variables, and then proceed through the code until it reaches a false .isPresented
. But something weird's going on with the first sheet.
Also weird is the fact that if you tap "Sheet 4" a second time through (i.e., Foundation -> 1 -> 2 -> 3 -> 4 -> 1 -> 2 -> 3 ->4) the Console prints out a bunch of goobledegook and "Sheet 2" appears, and then it's a continuous loop of 2 -> 3 -> 4 -> 2 -> .... Which makes even less sense to me than restarting at 1 the first time around.