I'm using this .if
extension which works great and should be added to SwiftUI, however it won't work in this case to check #available
because #available may only be used as condition of an 'if', 'guard' or 'while' statement
How can I make it work with this .if
, anyway?
//Does not compile for #available may only be used as condition of an 'if', 'guard' or 'while' statement
ForEach...
.if(#available(iOS 15.0, *)) { $0.refreshable {
} }
extension View {
@ViewBuilder
func `if`<Transform: View>(
_ condition: Bool,
transform: (Self) -> Transform
) -> some View {
if condition {
transform(self)
} else {
self
}
}
}