How to get label name from Button?
If you are sure that titleLabel
is not nil
:
println(TheButton.titleLabel!.text)
else
if let text = TheButton.titleLabel?.text {
println(text)
}
More simply, you could just do:
let titleValueString = TheButton.currentTitle!
If the button's title is not nil, the exclamation point (!
) will implicitly unwrap the optional (currentTitle without the exclamation point) and you will have a string value for the title of the button in your constant, titleValueString