Oh wow! Double assignments and a third different outcome with the same code of optional variables . So you have both a
and b
using both optional spellings.
If you comment out b
, now a
is nil instead of getting value assigned in init!
struct FooFooFoo: View {
@State var a: Int?
@State var b: Optional<Int> // 1. try comment this out
init() {
a = 1234
b = 4444 // 2. comment this out
}
var body: some View {
VStack {
Text("a = \(a ?? -1)")
Text("b = \(b ?? -1)") // 3. comment this out
}
}
}
So the exact same code behave differently depend on whether you have another optional variable is present or not!
Edit: see the conclusion to as why this is so: SwiftUI @State PW exact same code different result if another optional is added!? :=( - #9 by young