Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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