Skip to content

Instantly share code, notes, and snippets.

@steipete
Created February 24, 2021 10:51
Show Gist options
  • Save steipete/95d90786dac2fbae122d76c370cd5cd1 to your computer and use it in GitHub Desktop.
Save steipete/95d90786dac2fbae122d76c370cd5cd1 to your computer and use it in GitHub Desktop.
If you use it please credit PSPDFKit GmbH. MIT License
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