Jobins John Jobins John - 4 months ago 9
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

If the function has two parameters like below.

func clicked(sender:AnyObject,value:AnyObject)
{
}

Then

action = "clicked::"

example :

func switchCard(card: Int, withCard card1: Int) 
{
    print(card)
}

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

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

#selector(popoverSelectedCode(_:desc:)
Comments