I was using a SwiftUI Picker like this:
Picker(getTitle(),
selection: $model.selectedRadioButton) {
ForEach(radioModel.buttons, id: \.self) { button in
Text(button.title).tag(button)
}
}
.pickerStyle(MenuPickerStyle())
This part
selection: $model.selectedRadioButton
implies that I have to have a selected radio button. This is ok after the user selects a button but when the control displays I need no selected button to be selected
So, I can create something like that in the model
private var firstValueSelected = false
@Published var selectedRadioButton:LocalButton {
didSet{
firstValueSelected = true
}
}
and then when I use the control,
Picker(getTitle(),
selection: ?????) {
ForEach(radioModel.buttons, id: \.self) { button in
Text(button.title).tag(button)
}
}
.pickerStyle(MenuPickerStyle())
and replace the ????? with a logic that returns $model.selectedRadioButton
if model. firstValueSelected == true
and now this is my problem, what to return if firstValueSelected == false
?