Created
February 24, 2021 10:51
-
-
Save steipete/95d90786dac2fbae122d76c370cd5cd1 to your computer and use it in GitHub Desktop.
If you use it please credit PSPDFKit GmbH. MIT License
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
import Foundation | |
import SwiftUI | |
@available(iOS 13.0, *) | |
extension View { | |
/// Wraps view into an AnyView | |
func eraseToAnyView() -> AnyView { | |
AnyView(self) | |
} | |
/// Apply a view modifier conditionally | |
@ViewBuilder func applyIf<T: View>(_ condition: @autoclosure () -> Bool, apply: (Self) -> T) -> some View { | |
if condition() { | |
apply(self) | |
} else { | |
self | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment