I have the problem, to have a high amount of buttons which have a number as their label, so i thought i could take the label as an integer instead of creating an action for
If you want to do this, you can convert the string
to an Int
by using string.toInt()
such as:
if let input = sender.titleLabel?.text?.toInt() {
// do something with input
} else {
// The label couldn't be parsed into an int
}
However, I'd suggest either using UIView.tag
or subclassing UIButton
and adding an Int
property to it to accomplish this, in case you ever change the display of your labels.