I just started learning Swift recently and I was trying to use Pickers to get a scroll wheel of some type. I had a ForEach loop that went from 10-100 and I tried to get values back from the picker when a user selected one of those values, but I instead got the index of that value instead of the actual value. Is there a way to get the value and not the index?
Thank you
Thank you
Thanks.Yeah, here it is
It is very kind marking the point of interest, but code formatting would make it more readable.The Italicized and bolded part is the code that I am referencing
Please use Code block (icon <>) feature of this site.
There may be several ways, but in your case this would work:
Code Block Picker("Number of People:", selection: $numberOfPeople){ ForEach(1...100, id: \.self) { //<- Text("\($0) people") } }
When you use ForEach(_:id:), id of each element will be used as a selection value.