title: Error in URL Request "The operation couldn’t be completed. No such file or directory"
body: <p>Ever since the change in Swift syntax for URL requests after the update to 9.1, I've been getting an error making requests to my API. For example, this POST request which simply tries to login. I can log in just fine directly in the API (Strongloop Loopback) Explorer interface but not from Swift. I get this error:</p>
  
  <p><code>The operation couldn’t be completed. No such file or directory</code></p>
  
  <p>Here's what my code looks like:</p>
  
  <pre><code>func performLoginRequestWithURL(url: NSURL, email: String, password: String) {
              let bodyData = "email=\(email)&amp;password=\(password)"
              let request: NSMutableURLRequest = NSMutableURLRequest(URL: url)
              let session = NSURLSession.sharedSession()
              request.HTTPMethod = "POST"
              request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding)
  
              let task = session.dataTaskWithRequest(request, completionHandler: {
                  data, response, error -&gt; Void in
                  if let error = error {
                      let errString = error.localizedDescription
                      NSNotificationCenter.defaultCenter().postNotificationName(self.lh, object: nil, userInfo: ["Result": errString])
                      print(error.localizedDescription)
  
                  } else if data != nil {
                      let json = NSString(data: data!, encoding: NSUTF8StringEncoding) as! String
  
                      if let dictionary = JSON().parseJSON(json) as [String: AnyObject]? {
                          let accesstoken = dictionary["id"] as! String
                          let id = dictionary["userId"] as! Int
  
                          // MARK: - Store UID &amp; AccessToken
                          NSUserDefaults.standardUserDefaults().setBool(true, forKey: "userLoggedIn")
                          NSUserDefaults.standardUserDefaults().setInteger(id, forKey: "userId")
                          NSUserDefaults.standardUserDefaults().setObject(accesstoken, forKey: "accessToken")
                          NSUserDefaults.standardUserDefaults().synchronize()
                          NSNotificationCenter.defaultCenter().postNotificationName(self.lh, object: nil, userInfo: ["Result": "Success"])
                      }
                  }
  
              })
              task.resume()
          }
  </code></pre>
  
  <p>Here's what it used to look like back when it worked, but they depreciated the sendAsynchronousRequest method:</p>
  
  <pre><code>func performLoginRequestWithURL(url: NSURL, email: String, password: String) {
          let bodyData = "email=\(email)&amp;password=\(password)"
          var request: NSMutableURLRequest = NSMutableURLRequest(URL: url)
          request.HTTPMethod = "POST"
          request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding)
          NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()){
              response, data, error in
  
              if let error = error {
                  let errString = error.localizedDescription
                  NSNotificationCenter.defaultCenter().postNotificationName(self.lh, object: nil, userInfo: ["Result": errString])
  
              } else if data != nil {
                  let json = NSString(data: data, encoding: NSUTF8StringEncoding) as! String
  
                  if let dictionary = JSON().parseJSON(json) as [String: AnyObject]? {
                      let accesstoken = dictionary["id"] as! String
                      let id = dictionary["userId"] as! Int
                      var results = [String: AnyObject]()
                      results = ["at": accesstoken, "id": id]
  
                      // MARK: - Store UID &amp; AccessToken
                      NSUserDefaults.standardUserDefaults().setBool(true, forKey: "userLoggedIn")
                      NSUserDefaults.standardUserDefaults().setInteger(id, forKey: "userId")
                      NSUserDefaults.standardUserDefaults().setObject(accesstoken, forKey: "accessToken")
                      NSUserDefaults.standardUserDefaults().synchronize()
                      NSNotificationCenter.defaultCenter().postNotificationName(self.lh, object: nil, userInfo: ["Result": "Success"])
                  }
              }
  
          }
      }
  </code></pre>