Open onmyway133 opened 3 years ago
This is great, thx for sharing! I used this to overload the nil coalescing operator:
public func ??<T>(optional: Binding<T?>, defaultValue: T) -> Binding<T> {
Binding<T>(
get: { optional.wrappedValue ?? defaultValue },
set: { optional.wrappedValue = $0 }
)
}
// Usage
DatePicker("Date", selection: $date ?? Date()))
@basememara thanks for sharing, this is clever 👍
We can write our custom Binding
Then use in places where it needs Binding with non-optional value