I use this code to perform actions with button tag:
func a() {
print("a")
}
func b() {
print("b")
}
let arrayOfActions: [()] = [a(),b()]
@objc func buttonAction(sender: UIButton!) {
arrayOfActions[sender.tag-1]
}
But in this case the functions a() and b() are called. But I need only one function to be called.
switchis pointless. Thedefaultcase will never be executed and the code could even crash. Further theactionsyntax nowadays is@objc func buttonAction(_ sender: UIButton)arrayOfActionsalready calls the two functions.