Search code examples
iospickerpickerview

I need to populate a picker


I'm new programming in Swift, and what I need is a pickerView (done programmatically) that is populated with Json Data. I succeeded populating the picker with the name of the object, but I need to select the name and catch the id of the object that came in the Json Data.

I would really appreciate answers with lines of code.


Solution

  • • First create an array to store fetched 'id's. Save id like done in dataZoneName.

    • Then on picker didSelectRow delegate pick the id corresponding to the selected string using row index

    • Now idToken have the id for selected Name in picker.

    • Also move alamofire data fetch code from viewdidLoad to a separate function. Also declare a parameter for id of type string.