title: Swift, passing parameters in sender to function
body: <p>Firstly please don't mark this as a duplicate. I have been through all the other questions and answers and already improved the code I first had but I still can't figure out the last part. I have my final year project due tomorrow and would love to get this feature working. Thank you!! </p>
  
  <p>I have a custom callout from an annotation and when I click a button on it I want to get directions from the users location to that annotation. </p>
  
  <pre><code>  let buttonDirections = UIButton(frame: calloutView.directions.frame)
        buttonDirections.addTarget(self, action: #selector(FindParkingVC.getDirections(sender:)), for: .touchUpInside)
        calloutView.addSubview(buttonDirections) 
  
  
  
  
    func getDirections(sender: UIButton) {
  
    //error on this line saying UIbutton has no member view
    //obviously the sender is wrong but don't know how to fix it  
    if let anno = sender.view.annotation as? SpaceAnnotation
  
  
   {
  
          var place: MKPlacemark!
          if #available(iOS 10.0, *) {
              place = MKPlacemark(coordinate: anno.coordinate)
          } else {
              place = MKPlacemark(coordinate: anno.coordinate, addressDictionary: nil)
          }
          let destination = MKMapItem(placemark: place)
          destination.name = "Selected Parking Space"
          let regionDistance: CLLocationDistance = 1000
          let regionSpan = MKCoordinateRegionMakeWithDistance(anno.coordinate, regionDistance, regionDistance)
  
          let options = [MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center), MKLaunchOptionsMapSpanKey:  NSValue(mkCoordinateSpan: regionSpan.span), MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving] as [String : Any]
  
          MKMapItem.openMaps(with: [destination], launchOptions: options)
      }
  
  
  }
  </code></pre>
  
  <p>Now I previously had this all working when I was using the standard callout. The function worked perfectly like this. I'm not using the detailcalloutbutton now so i can't use this function. </p>
  
  <pre><code>func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
  
      if let anno = view.annotation as? SpaceAnnotation {
  
          var place: MKPlacemark!
          if #available(iOS 10.0, *) {
              place = MKPlacemark(coordinate: anno.coordinate)
          } else {
              place = MKPlacemark(coordinate: anno.coordinate, addressDictionary: nil)
          }
          let destination = MKMapItem(placemark: place)
          destination.name = "Selected Parking Space"
          let regionDistance: CLLocationDistance = 1000
          let regionSpan = MKCoordinateRegionMakeWithDistance(anno.coordinate, regionDistance, regionDistance)
  
          let options = [MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center), MKLaunchOptionsMapSpanKey:  NSValue(mkCoordinateSpan: regionSpan.span), MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving] as [String : Any]
  
          MKMapItem.openMaps(with: [destination], launchOptions: options)
      }
  
  
  }
  </code></pre>
  
  <p>EDIT</p>
  
  <p>This is how I am calling the CustomCallout View</p>
  
  <pre><code>  func mapView(_ mapView: MKMapView,
               didSelect view: MKAnnotationView)
  {
  
      if view.annotation is MKUserLocation
      {
          // Don't proceed with custom callout
          return
      }
  
      let SpaceAnnotation = view.annotation as! SpaceAnnotation
      let views = Bundle.main.loadNibNamed("CustomCalloutView", owner: nil, options: nil)
      let calloutView = views?[0] as! CustomCalloutView
  
  
  
      if SpaceAnnotation.temp3 != nil {
  
      calloutView.duration.text = "Available for " + SpaceAnnotation.temp3
      }
  
      if SpaceAnnotation.temp != nil {
  
      calloutView.price.text = "€" + SpaceAnnotation.temp
      }
  
      if SpaceAnnotation.temp2 != nil {
      calloutView.description_.text = "Description: "  + SpaceAnnotation.temp2
      }         
  
  
                let buttonDirections = UIButton(frame: calloutView.directions.frame)
        buttonDirections.addTarget(self, action: #selector(FindParkingVC.getDirections(sender:)), for: .touchUpInside)
        calloutView.addSubview(buttonDirections)
  
  
  
      calloutView.center = CGPoint(x: view.bounds.size.width / 2, y: -calloutView.bounds.size.height*0.52)
      view.addSubview(calloutView)
      mapView.setCenter((view.annotation?.coordinate)!, animated: true)
  }
  </code></pre>
  
  <p>Also maybe worth noting SpaceAnnotation is a class which contents the variables temp3 etc. so in the init it would have more of the following</p>
  
  <pre><code>temp3 = snapshotValue["duration"] as?  String
  </code></pre>