Swift switch statement error Type 'Binding<T>' has no member 'member'

This error is generated at the first case statement in my example code. Type 'Binding<AType>' has no member 'atype1'

If I change the order of the cases in the switch statement, it is always the first one which gives the error. In my code, if you delete the value of that first switch line, and type it in again, as soon as you have entered 'case .' the drop down menu will offer suggestions and you can see the atype1 & atype2 near the top of the list.

What am I doing wrong?

import SwiftUI

enum AType: CaseIterable {
    case atype1
    case atype2
    case unknown        // default
}

struct Peripheral: Identifiable {
    let id: Int
    let name: String
    var type: AType = .unknown
}

struct ContentView: View {
    @State private var peri = Peripheral(id: 1, name: "A")
    var body: some View {
        switch $peri.type {
        case .atype1:
            Text("Hello, $peri.name!")
        case .atype2:
            Text("Goodbye, $peri.name!")
        case .unknown:
            Text("Oh no!")
        }
        .padding()
    }
}

#Preview() {
    ContentView()
}

Does this solves your problem?

https://codermite.com/t/swift-switch-statement-error-binding-gadgetcategory-has-no-member-category1/

Thank you. Yes it does.

So my error is that I should directly access the category property of peri in the switch statement, ie

    switch peri.type {

not

    switch $peri.type {

The error message is misleading because the solution is on a previous line.

That query you reference was submitted subsequent to mine by about 1 hour, but has spookily similar text in it.

Swift switch statement error Type 'Binding&lt;T&gt;' has no member 'member'
 
 
Q