I have a button. I want to create on/off behaviour for this button. If user click first time I want to print off. If click second print off. How to do it?
for example I can add boolean value in my action. But if I have a lot of different actions I need to create new boolean variables. Is there another way?
var pressed = false
let button = UIButton()
button.addTarget(self, action: #selector(self.action), for: .touchUpInside)
@objc func action(sender: UIButton!) {
if pressed = false { //if button click first
pressed = true
print("off")
} else {//if button click again
pressed = false
print("on")
}
}