I recently changed some picker code in SwiftUI to use a CaseIterable Enum rather than an array of items.
Here is the enum:
enum ReturnTypes : String, CaseIterable {
case Scaler
case Vector
case Matrix
}
Here is the picker code:
NavigationView {
Form {
Picker("Return Type:", selection: $task.returnType) {
ForEach(ReturnTypes.allCases, id: \.self) { type in
Text(type.rawValue)
}
}
}
}
When I previously had the data in an array and used
let returnTypes = ["Scaler", "Vector", "Matrix"]
...
Picker("Return Type:", selection: $task.returnType) {
ForEach(0..<returnTypes.count, id: \.self) {
Text(returnTypes[$0])
}
}
the current value of task.returnType was displayed on the picker line of the form next to the chevron. Using the enum, the task.returnType is NOT displayed next to the chevron and when I drill down to the picker selection view nothing is checked and even if I select an item, I still don't get anything displayed next to the chevron. Anyone else run into this issue?