It's possible, just use Optional
instead of _ConditionalContent
.
Here is your correct overload:
func ifLet<T, V>(_ value: T?, then: (T) -> V) -> V? where V: View {
value.map(then)
}
And as you can see, you can just use map
from Optional
to produce your view.
// quick example
let optionalString: String? = "swift"
var body: some View {
optionalString.map { string in
Text(string)
}
}
Optional
conditionally conforms to View
when Wrapped
conforms to View
.