SwiftUI Binding from State

struct Foo: View {
    @State var bar = false

    var body: some View {
        Toggle($bar) { Text("Bar") } // $bar should be State<Bool>, but Toggle accepts Binding<Bool>
    }
}

Could someone explain to me how $bar is resolved?
Since it's @State<Bool> it should be of type State<Bool>, but Toggle seems to accept only Binding.

Disclaimer: I don't have Xcode 11, but only read the doc from apple's website (and watched a lot of online videos :blush:).

$bar is Binding<Bool>.
State<Value> has a property var delegateValue: Binding<Value>. Access $bar, which goes through delegateValue
https://github.com/apple/swift-evolution/blob/master/proposals/0258-property-delegates.md

1 Like