title: Why do my CLLocation functions stop working when I insert them into an action button?
body: <p>So I've been using this tutorial, <a href="http://www.veasoftware.com/tutorials/2014/10/18/xcode-6-tutorial-ios-8-current-location-in-swift" rel="nofollow">http://www.veasoftware.com/tutorials/2014/10/18/xcode-6-tutorial-ios-8-current-location-in-swift</a>, to learn how to get some basic location information using the CLLocation class. I got it to successfully run when I declare the delegates and other methods INSIDE the viewDidLoad. Yay! </p>
  
  <pre><code>import UIKit
  import CoreLocation
  
  class ProfileScreenViewController: UIViewController, CLLocationManagerDelegate    {
  
  let locationManager = CLLocationManager()
  
  @IBOutlet var userInfoLabel: UILabel!
  var currentUser = PFUser.currentUser()!
  
  override func viewDidLoad() {
      super.viewDidLoad()
      self.navigationItem.setHidesBackButton(true, animated:true);
  
          }
  
  
  
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  
  
  @IBAction func testUserInfoButton(sender: UIButton) {
      PFUser.logOut()
      var currentUser = PFUser.currentUser()
      self.navigationItem.setHidesBackButton(true, animated:true);
      self.navigationController?.popToRootViewControllerAnimated(true)
  }
  
  @IBAction func getLocationButton(sender: UIButton) {
      self.locationManager.delegate = self
      self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
      self.locationManager.requestWhenInUseAuthorization()
      self.locationManager.startUpdatingLocation()
  
      func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
          println("error " + error.localizedDescription)
      }
  
      func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
          CLGeocoder().reverseGeocodeLocation(manager.location, completionHandler: { (placemarks, error) -&gt; Void in
  
              if error != nil {
                  println("error" + error.localizedDescription)
              }
  
              if placemarks.count &gt; 0 {
                  let pm = placemarks[0] as CLPlacemark
                  self.displayLocationInfo(pm)
              } else {
                  println("Error " + error.localizedDescription)
              }
          })
      }
  
      func displayLocationInfo(placemark: CLPlacemark){
          locationManager.stopUpdatingLocation()
          println(placemark.locality)
          println(placemark.postalCode)
          println(placemark.administrativeArea)
          println(placemark.country)
      }
  
  
  
  }
  </code></pre>
  
  <p><a href="http://imgur.com/a/pI1tP" rel="nofollow">http://imgur.com/a/pI1tP</a></p>
  
  <p>However! When I try and move everything to a button action, everything falls apart. The code is the same, and I have no idea how to fix this. I tried re-typing over and over again. The errors keep telling me things like, "definition conflicts with previous value", or such and such view controller does not have a member name x. I even went to another tutorial, on another site, who essentially wrote the same code but into a button (like exactly what I'm trying to do). But they got it to work. </p>
  
  <p>After fiddling around, I got it down to 3 errors. But the frustrating thing is, it is still the exact same code that I got working before... I feel like I'm missing something here when I transfer code within a button, but I'm still a bit new to Swift/Xcode. </p>
  
  <p>As requested, WORKING code, without errors:</p>
  
  <pre><code>import UIKit
  import CoreLocation
  
  class ProfileScreenViewController: UIViewController, CLLocationManagerDelegate {
  
  let locationManager = CLLocationManager()
  
  @IBOutlet var userInfoLabel: UILabel!
  var currentUser = PFUser.currentUser()!
  
  override func viewDidLoad() {
      super.viewDidLoad()
      self.navigationItem.setHidesBackButton(true, animated:true);
  
      self.locationManager.delegate = self
      self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
      self.locationManager.requestWhenInUseAuthorization()
      self.locationManager.startUpdatingLocation()
  }
  
  func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
      println("error " + error.localizedDescription)
  }
  
  func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
      CLGeocoder().reverseGeocodeLocation(manager.location, completionHandler: { (placemarks, error) -&gt; Void in
  
          if error != nil {
              println("error" + error.localizedDescription)
          }
  
          if placemarks.count &gt; 0 {
              let pm = placemarks[0] as CLPlacemark
              self.displayLocationInfo(pm)
          } else {
              println("Error " + error.localizedDescription)
          }
      })
  }
  
  func displayLocationInfo(placemark: CLPlacemark){
          locationManager.stopUpdatingLocation()
          println(placemark.locality)
          println(placemark.postalCode)
          println(placemark.administrativeArea)
          println(placemark.country)
  }
  </code></pre>
  
  <p>Anyways, I thank you if you can take a look at the code, or perhaps have encountered something like this. It's such a small thing, but after 4 hours, I had to seek help. </p>
  
  <p>Sorry I had to link out my images... Stackoverflow didn't let me post images... Very unhelpful...</p>