Created
August 13, 2019 05:29
-
-
Save onevcat/028cff3c600ddb889b44487be99f1d0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
class Foo: ObservableObject { | |
@Published var toggle = false | |
} | |
struct ContentView: View { | |
@EnvironmentObject var foo: Foo | |
var body: some View { | |
VStack { | |
Text(foo.toggle ? "On" : "Off") | |
Outer() | |
} | |
} | |
} | |
struct Outer: View { | |
var body: some View { | |
Inner() | |
} | |
} | |
struct Inner: View { | |
@EnvironmentObject var foo: Foo | |
var body: some View { | |
Toggle(isOn: $foo.toggle) { | |
Text("Toggle!") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment