Post

Replies

Boosts

Views

Activity

Picker style .menu doesn't handle nil
Here's the code... import SwiftUI enum Side: String { case left case right } struct SideView: View { @State private var name: String = "" @State private var side: Side? = nil var body: some View { NavigationStack { Form { Section { TextField("Name", text: $name) Picker("Side", selection: $side) { Text("Left").tag(Side.left as Side?) Text("Right").tag(Side.right as Side?) } .pickerStyle(.menu) // displays with "Left" selected even though side is nil // .pickerStyle(.inline) // all the other styles work as expected, nothing initially selected // .pickerStyle(.palette) // .pickerStyle(.navigationLink) } } } } } #Preview("SideView") { SideView() } Even though side is nil the .menu style displays with "Left" selected. Try any of the other styles. They all display with nothing initially selected. As they should when side is nil. This seems like a bug and I've submitted feedback. ID: FB21685273 Whether it's a bug or not has anyone worked around this?
Topic: UI Frameworks SubTopic: SwiftUI
1
0
119
2w