Working with Picker in SwiftUI
I think we all agree that the greatest advantage of SwiftUI is the ability it offers to implement specific controls with just a couple of lines; that’s the exact opposite of UIKit, where even the simplest control needs several lines of code in order to properly initialize and configure it. So, just from that, it makes perfect sense why SwiftUI has gained so many fans since day one, and keeps doing so.
Even though SwiftUI is not perfect yet and there are many developers preferring UIKit over SwiftUI -and for good reasons-, we just can’t overlook that there are several natively provided controls (views according to SwiftUI’s terminology) which we can integrate in a SwiftUI view like a breeze. I’ve written about many of them in previous tutorials, and today I’m focusing on another one; the Picker view.
The Picker view is the number one candidate to use when it comes to give users a range of options to choose from. In SwiftUI, a picker can get various appearances pretty fast and painlessly; that’s quite helpful when different kind of pickers should appear in different places. Pickers can present any values we want to display as options to users. Configuring a picker does not require much time or effort; and in this post, you’re going to read everything you need in order to start using SwiftUI pickers right away.