Clement G Clement G - 8 months ago 84
Swift Question

Value of type '(UIButton) -> ()' has no member 'setTitle'

I have this error and can't find a way to solve it..

@IBAction func startBouton(_ sender: UIButton) {

if !isTimerWorking {
// (...)
startBouton.setTitle(title:"PAUSE", for: UIControlState.normal)
} else {
// (...)
startBouton.setTitle(title:"START", for: UIControlState.normal)


I searched on internet, and UIButton I found that UIButton has a setTitle member..

Thanks for your help

Answer Source

You should be using the sender parameter (which is the UIButton rather than startBouton (which is a function). The type in the error message gives you all the information you need:

(UIButton) -> ()

is a function that takes a UIButton and returns nil. So you're obviously not calling setTitle on a UIButton instance.