title: Thread 1: EXC_BAD_INSTRUCTION
body: <p>I am making this app where users can see their own location and other users location. I recently just got an error saying</p>
  
  <blockquote>
    <p>Thread 1: EXC_BAD_INSTRUCTION (code=EXC_1386_INVOP,subcode=0x0)</p>
  </blockquote>
  
  <p>at this line:</p>
  
  <pre><code>var lat = locationManager.location?.coordinate.latitude
  </code></pre>
  
  <p>I have not managed to fix it.</p>
  
  <p><strong>What is causing it and how can I fix it?</strong></p>
  
  <p>For any who might would like the rest of the code:</p>
  
  <pre><code>import UIKit
  import Parse
  import CoreLocation
  import MapKit
  
  
  class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
  
      var myLocation: [CLLocation] = []
  
      @IBOutlet weak var MapView: MKMapView!
      @IBOutlet var UsernameTextField: UITextField!
      @IBOutlet var PasswordTF: UITextField!
      @IBOutlet var EmailTF: UITextField!
  
      var locationManager: CLLocationManager!
  
      override func viewWillAppear(animated: Bool) {
          super.viewWillAppear(animated)
  
      }
  
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          // Do any additional setup after loading the view.
  
          let locationManager = CLLocationManager()
  
          let lat = locationManager.location!.coordinate.latitude
          let lon = locationManager.location!.coordinate.longitude
  
          let location = CLLocationCoordinate2D(latitude: lat, longitude: lon)
          let span = MKCoordinateSpanMake(0.05, 0.05)
          let region = MKCoordinateRegionMake(location, span)
          MapView!.setRegion(region, animated:  true)
  
          let anotation = MKPointAnnotation()
          anotation.coordinate = location
          anotation.title = "My tittle"
          anotation.subtitle = "My Subtitle"
  
          MapView!.addAnnotation(anotation)
  
          print("Welcome in MapViewController")
      }
  }
  </code></pre>