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.