Last active
December 10, 2020 09:59
-
-
Save shaps80/f61c0745843cf41cb7498a650c8ba54b to your computer and use it in GitHub Desktop.
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
extension View { | |
/// Conditionally apply modifiers to a view. | |
func `if`<Content: View>(_ condition: () -> Bool, content: (Self) -> Content) -> some View { | |
condition() ? | |
ViewBuilder.buildEither(first: content(self)) : | |
ViewBuilder.buildEither(second: self) | |
} | |
func `if`<Content: View>(_ condition: @autoclosure () -> Bool, content: (Self) -> Content) -> some View { | |
condition() ? | |
ViewBuilder.buildEither(first: content(self)) : | |
ViewBuilder.buildEither(second: self) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: