Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

checking UIButton Title in Swift

I have a button and title of the button is an integer.

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

I am trying to check the title of the button so convert it to an integer and use it in an if statement, but couldn't make it work.

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

I am new to swift , I might even have problem with my approach, your help will be appreciated.

like image 350
user3499983 Avatar asked Dec 26 '14 17:12

user3499983


People also ask

How do I change text in Swift?

Changing Text Font and Color To change the font, select the text box or highlight a portion of the text, and click the Fonts button in the Inspector. Or, press Cmd-T. To change the color, select the text box or highlight a portion of the text, and click the color button in the Inspector.


1 Answers

you should use button1.currentTitle

like image 153
ChikabuZ Avatar answered Sep 23 '22 01:09

ChikabuZ