Learning SwiftUI and having some difficulty in understanding @State. For example in the code below, why don't we use State variable (that is with $ sign) with if statement? Why only as Toggle argument? How do we differentiate both the states?
import SwiftUI
struct ContentView: View {
@State private var isFrown = true
var body: some View {
VStack
{
Text ("Check toggle state")
Toggle(isOn: $isFrown) {
Text("")
.padding()
if isFrown { //why not $isFrown here
Text("")
}
else {
Text("")
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}