[Solved] Basic Swift grammar


Your code does not compile. sender is Any, so you can’t access the property titleLabel directly. You either have to write:

guard let senderedText = (sender as? UIButton)?.titleLabel?.text else {
    return
}

Or change the parameter type:

@IBAction func inputformula(_ sender: UIButton) {

As you can see, I inferred sender to be a UIButton because UIButton has a titleLabel property. Hopefully this is what you are confused about.

The guard statement checks whether the text of the button is nil. If it is, return, otherwise carry on.

5

solved Basic Swift grammar