Skip to content

Instantly share code, notes, and snippets.

@chriseidhof
Created December 10, 2019 12:54
Show Gist options
  • Save chriseidhof/3ad94375e536088638ea4dcd98e0a0a9 to your computer and use it in GitHub Desktop.
Save chriseidhof/3ad94375e536088638ea4dcd98e0a0a9 to your computer and use it in GitHub Desktop.
struct Nested: View {
@State var counter = 0
init() {
print("Init")
}
var body: some View {
Button(action: { self.counter += 1 }, label: {
Text("Tap me! \(counter)")
})
}
}
struct ContentView: View {
@State var counter = 0
var body: some View {
VStack {
Button(action: { self.counter += 1 }, label: {
Text("Tap me! \(counter)")
})
.padding()
.background(Color.orange)
.cornerRadius(5)
Nested()
}
}
}
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