title: Swift Google Directions API JSON - EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
body: <p>I am trying to get directions data using Google API, but it's keep crashing. Here is my code:</p>
  
  <pre><code>let baseURLDirections = "https://maps.googleapis.com/maps/api/directions/json?"
  var selectedRoute: Dictionary&lt;NSObject, AnyObject&gt;!
  var overviewPolyline: Dictionary&lt;NSObject, AnyObject&gt;!
  var originCoordinate: CLLocationCoordinate2D!
  var destinationCoordinate: CLLocationCoordinate2D!
  var originAddress: String!
  var destinationAddress: String!
  
  func getDirections(origin: String, destination: String, waypoints: Array&lt;String&gt;!, travelMode: AnyObject!, completionHandler: ((status: String, success: Bool) -&gt; Void)) {
  
      var directionsURLString = baseURLDirections + "origin=" + origin + "&amp;destination=" + destination
  
      directionsURLString = directionsURLString.stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet())!
  
      let directionsURL = NSURL(string: directionsURLString)
      let urlRequest: NSMutableURLRequest = NSMutableURLRequest(URL: directionsURL!)
      let session = NSURLSession.sharedSession()
      let task = session.dataTaskWithRequest(urlRequest) {
          (data, response, error) -&gt; Void in
  
          do {
              let directionsData = NSData(contentsOfURL: directionsURL!)
              if let dictionary: Dictionary&lt;NSObject, AnyObject&gt; = try NSJSONSerialization.JSONObjectWithData(directionsData!, options: .MutableContainers) as? Dictionary&lt;NSObject, AnyObject&gt; {
  
                  let status = dictionary["status"] as! String
  
                  if status == "OK" {
                      self.selectedRoute = (dictionary["routes"] as! Array&lt;Dictionary&lt;NSObject, AnyObject&gt;&gt;)[0]
  
                      self.overviewPolyline = self.selectedRoute["overview_polyline"] as! Dictionary&lt;NSObject, AnyObject&gt;
  
                      let legs = self.selectedRoute["legs"] as! Array&lt;Dictionary&lt;NSObject, AnyObject&gt;&gt;
  
                      let startLocationDictionary = legs[0]["start_location"] as! Dictionary&lt;NSObject, AnyObject&gt;
                      self.originCoordinate = CLLocationCoordinate2DMake(startLocationDictionary["lat"] as! Double, startLocationDictionary["lng"] as! Double)
  
                      let endLocationDictionary = legs[legs.count - 1]["end_location"]as! Dictionary&lt;NSObject, AnyObject&gt;
                      self.destinationCoordinate = CLLocationCoordinate2DMake(endLocationDictionary["lat"] as! Double, endLocationDictionary["lng"] as! Double)
  
                      self.originAddress = legs[0]["start_address"]as! String
                      self.destinationAddress = legs[legs.count - 1]["end_address"]as! String
  
                      self.calculateTotalDistanceAndDuration()
  
                      completionHandler(status: status, success: true)
                  }
                  else {
                      completionHandler(status: status, success: false)
                  }
              }
          } catch let error as NSError {
              print(error)
              completionHandler(status: "", success: false)
          }
      }
  
      task.resume()
  }
  </code></pre>
  
  <p>It says "EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)" on </p>
  
  <pre><code>self.overviewPolyline = self.selectedRoute["overview_polyline"] as! Dictionary&lt;NSObject, AnyObject&gt;
  </code></pre>
  
  <p>and even when I delete all of the code inside</p>
  
  <pre><code>if let dictionary: Dictionary&lt;NSObject, AnyObject&gt; = try NSJSONSerialization.JSONObjectWithData(directionsData!, options: .MutableContainers) as? Dictionary&lt;NSObject, AnyObject&gt; {
  </code></pre>
  
  <p>I am getting EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0).
  How do I solve this?</p>