Checking UIButton Header in Swift

I have a button, and the button name is an integer.

correctAnswer = randomNumber1 + randomNumber2 button1.setTitle("\(correctAnswer)", forState: UIControlState.Normal) 

I am trying to check the title of a button to convert it to an integer and use it in an if statement, but could not get it to work.

 button1.titleLabel?.text?.toInt() if button1.titleLabel == correctAnswer { //most probably I am making a mistake here. scoring() } else { println(button1.titleLabel?.text!) 

I'm new to fast, I might even have a problem with my approach, your help would be appreciated.

+6
source share
2 answers

you should use button1.currentTitle

+18
source

also you should use

  sender.currentTitle 
+1
source

Source: https://habr.com/ru/post/980181/


All Articles