title: Swift: How to Return to Earlier Function After didFailWithError
body: <p>I was wondering if I could get some advice on how to have an app recover and start working again after an error, or how to avoid the error in the first place. I have a code that prints "Success" if the App is close enough to a certain coordinate, and "Not close enough" if not within the area. This seems to work fine. However, when I simulate an area that's too far away, then switch to an area in range, then back to an area that's out of range, I encounter an error and it stops updating the location. So it prints "Success", then "Not close enough", then "Error: downThe operation couldn’t be completed. (kCLErrorDomain error 0.)". This also happens if I start from an area that's in range and switch to an area that's out of range - for some reason it's fine if it starts out of range and moves into range but not the opposite. </p>
  
  <pre><code>import UIKit
  import CoreLocation
  import AudioToolbox
  
  class ViewController: UIViewController, CLLocationManagerDelegate {
  
  let locationManager = CLLocationManager()
  
  override func viewDidLoad() {
      super.viewDidLoad()
      // Do any additional setup after loading the view, typically from a nib.
      self.locationManager.delegate = self
      self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
      self.locationManager.requestWhenInUseAuthorization()
      self.locationManager.startUpdatingLocation()
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  
  
  func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
  
      CLGeocoder().reverseGeocodeLocation(manager.location, completionHandler: {(placemarks, error)-&gt;Void in
  
          if (error != nil)
      {
          println("Error: " + error.localizedDescription)
          return
      }
  
          if placemarks.count &gt; 0{
          let pm = placemarks[0] as CLPlacemark
          self.displayLocationInfo(pm)
          self.playSound(pm)
      }
          else {
              println("Error with the data.")
          }
  
      })
  
  
  }
  
  func displayLocationInfo(placemark: CLPlacemark)
  {
      println(placemark.locality)
      println(placemark.postalCode)
      println(placemark.administrativeArea)
      println(placemark.country)
      println(locationManager.location.coordinate.latitude)
      println(locationManager.location.coordinate.longitude)
  }
  
  func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!){
      println("Error: down" + error.localizedDescription)
      return
  }
  
  func playSound(placemark: CLPlacemark)
  {
      if locationManager.location.coordinate.latitude &gt; 44.638832 &amp;&amp; locationManager.location.coordinate.latitude &lt; 44.638834 {
          AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
          println("success")
      }
      else {
          println("Not close enough")
          return
      }
  }
  
  }
  </code></pre>
  
  <p>It's this error function that's giving me trouble:</p>
  
  <pre><code>func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!){
      println("Error: down" + error.localizedDescription)
      return
  }
  </code></pre>
  
  <p>I'm quite new to Swift, so hopefully this is just a simple case of having functions in the wrong order or not including some basic syntax. Any help is greatly appreciated!</p>
  
  <p>EDIT: I think I solved it. Took "return" out of the last else statement, and now after 10 seconds it recovers from the error and starts showing location updates again.</p>