title: How do I pass data between functions in this Firebase situation? Swift + Xcode
body: <p>I am very new to Swift. How would I retrieve my annotation from the addPin function and be able to use it in my addLocation action (buttonPressed). I am trying to add a pin on to a map using a force touch, type in a name and information in two separate text fields, and add these four pieces of information to my Firebase Database where they can be retrieved and plotted on another map. Similar to how the app Flush works.</p>
  
  <p>class AddLocationViewController: UIViewController {</p>
  
  <pre><code>@IBOutlet weak var nameTF : UITextField!
  @IBOutlet weak var descriptionTF : UITextField!
  @IBOutlet weak var longitudeTF : UITextField!
  @IBOutlet weak var latitudeTF : UITextField!
  
  @IBOutlet weak var addButton : UIButton!
  
  @IBOutlet weak var readySwitch: UISwitch!
  
  
  @IBAction func addLocation ( _ sender : Any? ) {
  
        if let name = nameTF.text,
          let info = descriptionTF.text,
          let latitude = Optional(annotation.coordinate.latitude) ,
          let longitude = Optional(annotation.coordinate.longitude),
          name.isEmpty == false {
  
            let dict : [String:Any] = ["name":name, "info":info, "latitude": latitude, "longitude":longitude]
  
            let ref = Database.database().reference()
  
             let newPointRef = ref.child("annotations").childByAutoId()
             ref.child("annotations").child(newPointRef.key).setValue(dict)
  
             }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>@IBAction func textChanged ( _ sender : Any? ) {
      validateUserInterface()
  }
  
  
  func validateUserInterface () {
      addButton.isEnabled = false
      guard let name = nameTF.text, name.isEmpty == false else { return 
  
      if let _ = CLLocationDegrees( latitudeTF.text ?? "" ),
          let _ = CLLocationDegrees( longitudeTF.text ?? "" )
          /*let location = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)*/ {
          addButton.isEnabled = true
      }
  }
  
  override func viewDidLoad() {
      super.viewDidLoad()
      validateUserInterface()
  }
  
  @IBOutlet weak var addCourtMapView: MKMapView!
  
  
  @IBAction func addPin(_ sender: UILongPressGestureRecognizer) {
  
      let location = sender.location(in: self.addCourtMapView)
      let locCoord = self.addCourtMapView.convert(location, toCoordinateFrom: self.addCourtMapView)
  
      let annotation = MKPointAnnotation()
  
     annotation.coordinate = locCoord
     annotation.title = "New Court"
      annotation.subtitle = "The court is located here"
     self.addCourtMapView.removeAnnotations(addCourtMapView.annotations)
    self.addCourtMapView.addAnnotation(annotation)
  
   }
  </code></pre>
  
  <p>}</p>