Post

Replies

Boosts

Views

Activity

Reply to Picker the selection "" is invalid and does not have an associated tag, this will give undefined results
A possible approach is to set the "selection" value to an actual option in the initializer. This avoids the need to add a tag for an empty selection. struct PickerTest: View {     @State private var selectOption: [String] = ["1","2","3"]     @State private var fieldValue: String = ""     init() {         self._fieldValue = State(initialValue: selectOption.first ?? "")     }     var body: some View {         Picker("Select number", selection: $fieldValue){             ForEach(selectOption, id: \.self){                 Text($0)             }         }     } }
Nov ’22