How do I get a Picker to show initial and selected value?

I am using a Picker in a macOS app but it does not show the initial value nor the selected value after choosing it.

I can reproduce the problem with this simple View:
Code Block
struct ContentView: View {
  @State private var pickedValue: UInt8 = 1
  var body: some View {
    Picker("Pick Something: ", selection: $pickedValue) {
      Text("One").tag(1)
      Text("Two").tag(2)
    }
    .padding()
  }
}

The default mode is Menu mode, and I want to it show "One" when first starting, and then whatever the user selects. It does not show anything.
After selecting something, it also does not show the selection but it does get a check-mark at the selected item if I click on it again.

I've tried different picker styles but they all give the same problem.

Accepted Reply

I found that changing my picker to use an Enum works:
Code Block
Picker("Pick Something: ", selection: $pickedValue) {
ForEach(TestState.allCases) { state in
Text(state.rawValue).tag(state)
}
}

Why would this work differently from the initial code?

TestState is declared:
Code Block
enum TestState: String, CaseIterable, Identifiable {
  case one
  case two
  var id: String { self.rawValue }
}


Replies

I found that changing my picker to use an Enum works:
Code Block
Picker("Pick Something: ", selection: $pickedValue) {
ForEach(TestState.allCases) { state in
Text(state.rawValue).tag(state)
}
}

Why would this work differently from the initial code?

TestState is declared:
Code Block
enum TestState: String, CaseIterable, Identifiable {
  case one
  case two
  var id: String { self.rawValue }
}