Created
June 4, 2021 20:54
-
-
Save davbeck/c970960ed72b1f54596ec0fd6a4e7ab0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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