-1

I am trying to set up my MKMapView so that when I press and hold the map for 2 seconds, a pin will appear at the user's current location.

Here is what I have in my viewDidLoad:

let gestureRecognizer = UILongPressGestureRecognizer(target: self, action:(Selector(("longPress:"))))
gestureRecognizer.minimumPressDuration = 2.0
gestureRecognizer.delegate = self
map.addGestureRecognizer(gestureRecognizer)

Then at the bottom of my ViewController class I have the following:

func longPress(gestureRecognizer: UILongPressGestureRecognizer) {

    let coordinate = map.centerCoordinate

    let annotation = MKPointAnnotation()
    annotation.coordinate = coordinate
    map.addAnnotation(annotation)
}

When I run the app and press on the map for 2 seconds, the app crashes. The console says

terminating with uncaught exception of type NSException

and

unrecognized selector sent to instance 0x7f89f0c02ad0

and I am not sure why. Thank you for any guidance you can offer.

nynohu
  • 1,628
  • 12
  • 12
Evan C
  • 53
  • 1
  • 7
  • http://stackoverflow.com/questions/24681275/how-to-do-a-long-press-in-swift –  Feb 13 '17 at 00:16

1 Answers1

0

Never say

Selector(("longPress:"))

Say

#selector(longPress)
matt
  • 515,959
  • 87
  • 875
  • 1,141