Does anyone know how to create a picker in SwiftUI.
I'm struggling with the content parameter.
This is as far as I've got
Picker(selection: $abindingi, label: "", content:{ return []})
Does anyone know how to create a picker in SwiftUI.
I'm struggling with the content parameter.
This is as far as I've got
Picker(selection: $abindingi, label: "", content:{ return []})
I solved it.
Picker(selection: $setting.whereami, label: Text("Location"))
{
ForEach(setting.locations) { location in
Text(location.id).tag(location.id)
}
}
Note that my location class needed to conform to Identifable, that was the problem.
import Foundation
import SwiftUI
struct Location: Identifiable
{
var id: String = ""
}
Code Block import SwiftUI struct OnlyYou: View { @State var selected: String = "" let toSelect = ["aErnährung", "KörperPflege", "Reinigung"] var body: some View { VStack { Picker("Select..", selection: $selected) { ForEach(toSelect, id: \.self) { select in Text(select) } } Text("you selected: \(selected)") } } } struct OnlyYou_Previews: PreviewProvider { static var previews: some View { OnlyYou() } }