Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type "myViewController" does not conform to protocol UIPIckerDataSource in Swift

I just create a new class in Swift, it's called myViewController and it's a UIViewController. Now I'm trying to make it a UIPickerViewDelegate and DataSource but i got a strange error

import UIKit  class myViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {    ... } 

It says Type "myViewController" does not conform to protocol UIPIckerDataSource over the UIPickerViewDataSource.

Is it a bug of Xcode-Beta 3??

Screenshot for compile-time error

like image 837
r4id4 Avatar asked Jul 26 '14 12:07

r4id4


2 Answers

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.

like image 85
salman140 Avatar answered Sep 22 '22 07:09

salman140


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 } 
like image 23
offbyone Avatar answered Sep 20 '22 07:09

offbyone