Skip to content

Instantly share code, notes, and snippets.

@quindariuss
Created March 8, 2020 04:29
Show Gist options
  • Save quindariuss/0d7ab0bd5ec1d8eb36641ac735ae48ac to your computer and use it in GitHub Desktop.
Save quindariuss/0d7ab0bd5ec1d8eb36641ac735ae48ac to your computer and use it in GitHub Desktop.
how to pass functions and make resuable buttons in swiftUI
struct ChildView: View {
var function: () -> Void
var body: some View {
Button(action: {
self.function()
}, label: {
Text("Button")
})
}
}
struct ContentView: View {
var body: some View {
ChildView(function: { self.setViewBackToNil() })
}
func setViewBackToNil() {
print("I am the parent")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment