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. The code file for the sample is included in the swift_3_oop_chapter_08_09
folder.
class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource { @IBOutlet weak var picker: UIPickerView! private var gamesList: [Game] = [Game]() override func viewDidLoad() { super.viewDidLoad() // Do any additional setup...