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()
}