Skip to content

Instantly share code, notes, and snippets.

@tieleman
Created April 23, 2020 11:45
Show Gist options
  • Save tieleman/ecf25c29a9184ed65dadfc7824a98e61 to your computer and use it in GitHub Desktop.
Save tieleman/ecf25c29a9184ed65dadfc7824a98e61 to your computer and use it in GitHub Desktop.
// Put in top level file scope
extension View {
func eraseToAnyView() -> AnyView {
AnyView(self)
}
}
private func buildComplexButton() -> some View {
if someConditional {
return Button(action: { /* do something */ }) {
Text("1")
}.eraseToAnyView()
} else {
return Button(action: { /* do something else */ }) {
Image(systemName: "faceid")
}.eraseToAnyView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment