Type "myViewController" does not conform to protocol UIPIckerDataSource in Swift
You need to implement all the required methods of UIPickerViewDataSource
and UIPickerViewDelegate
, if you want to conform to these protocols.
Swift is more like java when it comes to protocols because if you don't implement all the required methods declared by a protocol you are going to get a compile time error instead of a run time exception.
Fix-it in XCode 8.1 inserts a deprecated version of the method below if you're using Swift 3:
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int { return componentNumber}
In XCode 10.0+
func numberOfComponents(in pickerView: UIPickerView) -> Int { return componentNumber}
Implement required method of UIPickerDataSource
as in documentation.
The data source provides the picker view with the number of components, and the number of rows in each component, for displaying the picker view data. Both methods in this protocol are required.
So you need to implement these methods
func numberOfComponentsInPickerView(_ pickerView: UIPickerView!) -> Int {} func pickerView(_ pickerView: UIPickerView!,numberOfRowsInComponent component: Int) -> Int{}