Created
March 8, 2020 04:29
-
-
Save quindariuss/0d7ab0bd5ec1d8eb36641ac735ae48ac to your computer and use it in GitHub Desktop.
how to pass functions and make resuable buttons in swiftUI
This file contains 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
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