Jobins John Jobins John - 1 year ago 45
Swift Question

How to pass an extra parameter

I need to pass an extra parameter to the following line of code

let lpGestureRecognizer: UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(didLongPressCell))

I need to send the cell that was long pressed also. Is there any way to do that

Thanks in advance

Answer Source

If the function has two parameters like below.

func clicked(sender:AnyObject,value:AnyObject)


action = "clicked::"

example :

func switchCard(card: Int, withCard card1: Int) 

let singleTap1 = UITapGestureRecognizer(target: self, action: "switchCard:withCard:")

Just a note on Swift 2.2. You can now type the selector as