The UIPicker is the scroll wheel that shows all the available currencies that we can query the API for a Bitcoin price. It’s a neat way of selecting options without having to have a load of buttons take up screen real estate. There are just a few steps that are required to set it up though. Let’s do it together.

This says that the ViewController class is capable of providing data to any UIPickerViews. But actually, we don’t have all the required methods implemented. #fakeItTillYouMakeIt

Next, let’s update the PickerView with some titles and detect when it is interacted with. To do this we have set up the PickerView’s delegate methods.

This method expects a String as an output. The String is the title for a given row. When the PickerView is loading up, it will ask its delegate for a row title and call the above method once for every row. So when it is trying to get the title for the first row, it will pass in a row value of 0 and a component (column) value of 0.

Great. We’ve got a functioning Picker View. But nothing happens when you make a selection. Let’s change that.

This will get called every time when the user scrolls the picker. When that happens it will record the row number that was selected.

Ok. Using the row number is actually pretty unintuitive. Let’s change that print statement to print the currency selected instead.

SOLUTION

Check out the solution to this challenge step by cloning the project from the link below:

https://github.com/appbrewery/ByteCoin-iOS13-Completed/tree/Step-2-Solution