Make your State variable optional
@State private var selectedCategoryIndex = Int?
2. Provide an option for "No selection" and tag it with nil as an optional Int to match it. Place it before or after your ForEach
Text("Nothing").tag(nil as Int?)
// ForEach here
3. Cast your actual values as Optionals the same way
// ForEach here
Text(categories[$0].name!).tag($0 as Int?)
I'd also consider using the actual object array in your Picker rather than the indices.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: