title: Set timeout in Alamofire
body: <p>I am using Alamofire 4.0.1 and <strong>I want to set a timeout for my request</strong>. I tried the solutions gived in this <a href="https://stackoverflow.com/questions/36626075/handle-timeout-with-alamofire">question</a>:</p>
  
  <p><strong>In the first case</strong>, it throws a <strong><em>NSURLErrorDomain</em></strong> (timeout is set correctly):</p>
  
  <pre><code>let configuration = URLSessionConfiguration.default
  configuration.timeoutIntervalForRequest = 10
  
      let sessionManager = Alamofire.SessionManager(configuration: configuration)
      sessionManager.request("yourUrl", method: .post, parameters: ["parameterKey": "value"])
              .responseJSON {
                  response in
                  switch (response.result) {
                  case .success:
                      //do json stuff
                      break
                  case .failure(let error):
                      if error._code == NSURLErrorTimedOut {
                          //timeout here
                      }
                      print("\n\nAuth request failed with error:\n \(error)")
                      break
                  }
              }
  </code></pre>
  
  <p><strong>In the second case</strong>, the time out is not replaced and still set as 60 seconds.</p>
  
  <pre><code>let manager = Alamofire.SessionManager.default
  manager.session.configuration.timeoutIntervalForRequest = 10
  
  manager.request("yourUrl", method: .post, parameters: ["parameterKey": "value"])
  </code></pre>
  
  <p><strong>I am running in ios 10.1</strong></p>
  
  <p><strong>My code:</strong> (it doesn't work)</p>
  
  <pre><code>    let configuration = URLSessionConfiguration.default
      configuration.timeoutIntervalForRequest = 10 // seconds
      configuration.timeoutIntervalForResource = 10
      let alamoFireManager = Alamofire.SessionManager(configuration: configuration)
  
      alamoFireManager.request("my_url", method: .post, parameters: parameters).responseJSON { response in
  
  
          switch (response.result) {
          case .success:
                   //Success....
              break
          case .failure(let error):
              // failure...
              break
          }
      }
  </code></pre>
  
  <p><strong>Solved Alamofire github thread:</strong> <a href="https://github.com/Alamofire/Alamofire/issues/1931#issuecomment-274826417" rel="noreferrer">Alamofire 4.3.0 setting timeout throws NSURLErrorDomain error #1931</a></p>