Skip to content

Instantly share code, notes, and snippets.

@kumamotone
Created November 11, 2019 12:21
Show Gist options
  • Save kumamotone/b070150250915455cc326eef3299fec4 to your computer and use it in GitHub Desktop.
Save kumamotone/b070150250915455cc326eef3299fec4 to your computer and use it in GitHub Desktop.
import SwiftUI
struct GameSettings {
var isHard: Bool = false
}
struct NextView: View {
@Binding var settings: GameSettings
var body: some View {
Toggle(isOn: $settings.isHard) {
if self.settings.isHard {
Text("Hard")
} else {
Text("Easy")
}
}
}
}
struct ContentView: View {
@State var settings: GameSettings = GameSettings()
var body: some View {
NavigationView {
List {
NavigationLink(destination: NextView(settings: $settings)) {
Text("\(settings.isHard ? "Hard" : "Easy")")
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment