I am trying to pass an extra parameter to the buttonClicked action, but cannot work out what the syntax should be in Swift. button.addTarget(self, action: "buttonClicked:", forControlEvents:
original source : https://stackoverflow.com/questions/24814646/attach-parameter-to-button-addtarget-action-in-swift
You cannot pass custom parameters in addTarget:.One alternative is set the tag property of button and do work based on the tag.
button.tag = 5 button.addTarget(self, action: "buttonClicked:", forControlEvents: UIControlEvents.TouchUpInside)
Or for Swift 2.2 and greater:
button.tag = 5 button.addTarget(self,action:#selector(buttonClicked), forControlEvents:.TouchUpInside)
Now do logic based on tag property
@objc func buttonClicked(sender:UIButton) { if(sender.tag == 5){ var abc = "argOne" //Do something for tag 5 } print("hello") }








