Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import SwiftUI
func ?? <T>(optional: Binding<T?>, defaultValue: @escaping @autoclosure () -> T) -> Binding<T> {
return Binding {
optional.wrappedValue ?? defaultValue()
} set: { newValue in
optional.wrappedValue = newValue
}
}
func ?? <T>(optional: Binding<T?>, defaultValue: @escaping @autoclosure () -> T?) -> Binding<T?> {
return Binding {
optional.wrappedValue ?? defaultValue()
} set: { newValue in
optional.wrappedValue = newValue
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment