Retrieving the name of a button on the Swift sender

2

How do I retrieve the value of a button?

For example:

I have a button in my layout with the name Test button , but I want to assign the name of this button to be clicked on a variable!

Is this possible?

Thank you ] 1

    
asked by anonymous 22.01.2016 / 16:59

2 answers

1

Just get the sender.titleLabel.text , as it is a UIButton , there is no property value

Since your sender is AnyObject , you'll need to cast it

let value = sender.titleLabel.text as! String

If you use this button-only method, I recommend moving from AnyObject to UIButton

Edit You need to get the label of the button ( titleLabel ) and then get the text ( text ) as above example

    
22.01.2016 / 17:46
2

To do this, you need to check the sender.tag property and use its name to identify which button is being triggered.

    
22.01.2016 / 17:40