O'Reilly logo

Object–Oriented Programming with Swift 2 by Gastón C. Hillar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Interacting with an object-oriented data repository through Picker View

Now, we have to add code to the ViewController class in the ViewController.swift source file to make the class conform to two additional protocols: UIPickerViewDataSource and UIPickerViewDelegate. The conformance to the UIPickerViewDataSource protocol allows us to use the class as a data source for the UIPickerView class that represents the Picker View component. The conformance to the UIPickerViewDelegate protocol allows us to handle the events raised by the UIPickerView class.

The following lines show the new code for the ViewController class:

class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {

    @IBOutlet weak var picker: UIPickerView!
    

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required