title: Using parameters in action of UITapGestureRecognizer in Swift
body: <p>I am trying to call a function with parameters using the action of <code>UITapGestureRecognizer</code> and I can't figure out any alternative.</p>
  
  <p>This here is the gesture that is suppose to call the doubleTap function with the <code>indexPath</code> parameter.</p>
  
  <pre><code>var gestureDoubleTap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "doubleTap(indexPath)")
  </code></pre>
  
  <p>This here is the function that is suppose to be called.</p>
  
  <pre><code>func doubleTap(indexPath: NSIndexPath) {
      NSLog("double tap")
      NSLog("%@", indexPath.row)
  }
  </code></pre>
  
  <p>How can I call the <code>doubleTap</code> function with the <code>indexPath</code> parameter?</p>
  
  <p>Thank you for all suggestions.     </p>
  
  <p><strong><em>EDIT</em></strong> - this is my whole code, it is basically setting up the object 'name' so my second viewController can get it and use it</p>
  
  <pre><code>import UIKit
  class viewController1: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
  
      @IBOutlet weak var collectionView: UICollectionView!
      var imageArray:[String] = []
      var name : AnyObject? {
          get {
          return NSUserDefaults.standardUserDefaults().objectForKey("name")
          }
          set {
              NSUserDefaults.standardUserDefaults().setObject(newValue!, forKey: "name")
              NSUserDefaults.standardUserDefaults().synchronize()
          }
      }
  
      func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
          return imageArray.count
      }
  
      func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -&gt; UICollectionViewCell {
          var cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as myViewCell
  
          //adding single and double tap gestures for each cell
          /////////////////////////////
          //ISSUE IS SENDING indexPath TO doubleTap FUNC
          var gestureDoubleTap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "doubleTap:")
          gestureDoubleTap.numberOfTapsRequired = 2
          cell.addGestureRecognizer(gestureDoubleTap)
  
          var gestureSingleTap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "singleTap")
          gestureSingleTap.numberOfTapsRequired = 1
          cell.addGestureRecognizer(gestureSingleTap)
  
          cell.imgView.image=UIImage(named: imageArray[indexPath.row])        
          return cell
      }
  
      //func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath){
      //
      //    name = imageArray[indexPath.row]
      //}
  
      override func viewDidLoad(){
          super.viewDidLoad()
          imageArray=["1.png","2.png","2.png","1.png","1.png","2.png","1.png","2.png","1.png","2.png","1.png","2.png","1.png","2.png","1.png","2.png"]
  
      }
  
      func doubleTap(sender: UITapGestureRecognizer) {
          var tapLocation = sender.locationInView(self.collectionView)
  
          var indexPath:NSIndexPath = self.collectionView.indexPathForItemAtPoint(tapLocation)!
  
          //var cell = self.collectionView.cellForItemAtIndexPath(indexPath)
  
          NSLog("double tap")
          NSLog("%@", indexPath)
  
          //NSLog("%@", cell!)
          //THIS IS THE GOAL----- set 'name' with the appropriate img      corresponding the cell
          //name = imageArray[indexPath]
          //self.performSegueWithIdentifier("segue", sender: nil)
      }
  
      func singleTap() {
          NSLog("single tap")
      }
  }
  </code></pre>