SwiftUI Picker With Optional Selection
A SwiftUI picker expects a binding to a selection, such as a project ID. The ForEach loop in a picker automatically applies a tag to each item using the project's ID. When a picker item is selected, the picker's binding is set to the selected item's ID. Sometimes, a picker needs to work with an optional binding, allowing for no selection. To achieve this, each picker item needs to be manually tagged with an optional identifier. The tag modifier has a parameter to indicate that the tag is optional, which defaults to true. To include a "None" option, a Text view with a nil value cast as an optional project ID can be added to the picker. The full project picker with optional selection includes a "None" option and manual tagging of each item with its project ID. The selection binding is declared as an optional project ID. The picker's body includes a label and a picker selection with the "None" option and the ForEach loop with manual tagging.