aboutsummaryrefslogtreecommitdiff
path: root/Map/Extensions/Binding+unwrap.swift
blob: 3498cc377dc08d156aa52e75b1b38c1d2c92d88f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
import SwiftUI

extension Binding {
    init(_ source: Binding<Value?>, _ defaultValue: Value) {
        // Ensure a non-nil value in `source`.
        if source.wrappedValue == nil {
            source.wrappedValue = defaultValue
        }
        // Unsafe unwrap because *we* know it's non-nil now.
        self.init(source)!
    }
}