我正在使用这个.if
效果很好的扩展,应该添加到 SwiftUI,但是在这种情况下它无法检查#available
,因为无论如何#available may only be used as condition of an 'if', 'guard' or 'while' statement
我怎样才能让它与这个一起工作.if
?
//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
}
}
}