Skip to content

Instantly share code, notes, and snippets.

@smsdm4
Created October 18, 2024 10:46
Show Gist options
  • Save smsdm4/0fe3a48fc0c3625246cc9b2cbfcc91b5 to your computer and use it in GitHub Desktop.
Save smsdm4/0fe3a48fc0c3625246cc9b2cbfcc91b5 to your computer and use it in GitHub Desktop.
SwiftUI @State 5
struct ContentView: View {
@State private var isOn = false
var body: some View {
ToggleView(isOn: $isOn)
}
}
struct ToggleView: View {
@Binding var isOn: Bool
var body: some View {
Toggle(isOn: $isOn) {
Text("Toggle is \(isOn ? "ON" : "OFF")")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment