Skip to content

Instantly share code, notes, and snippets.

@siracusa
Created July 11, 2022 14:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siracusa/5beb23628c7ab0fb8cc646862c557cb3 to your computer and use it in GitHub Desktop.
Save siracusa/5beb23628c7ab0fb8cc646862c557cb3 to your computer and use it in GitHub Desktop.
SwiftUI .if modifier
extension View {
@ViewBuilder
func `if`<Content: View>(_ conditional: Bool, @ViewBuilder content: (Self) -> Content) -> some View {
if conditional {
content(self)
}
else {
self
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment