I want to create a function so when a button gets pressed, the content of a variable changes. The function does get called, but I can't use any external variables inside it.
This is the code I'm having trouble with:
class Responder: NSObject {
func pressed(sender: UIButton) {
// Can't change the value of "a" here
}
}
var a: Int = 0
let responder = Responder()
let bt = UIButton(frame: CGRect(x: 0.0, y: 0.0, width: 200.0, height: 200.0))
bt.addTarget(responder, action: #selector(Responder.pressed), for: .touchUpInside)
What can I do to make this work?