Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting client-side timeout per request with Alamofire [swift]?

I'm trying to set a client-side timeout per request for Alamofire for Swift. The lead architect told me to set this on NSURLRequest, but I'm completely confused on how to actually do that in practice.

Can someone who has done this give an example? Thanks!

like image 620
Troy Payne Avatar asked Nov 25 '14 20:11

Troy Payne


1 Answers

I think this code may works.

var alamofireManager : Alamofire.Manager?

func some(){
  let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
  configuration.timeoutIntervalForResource = 2 // seconds

  self.alamofireManager = Alamofire.Manager(configuration: configuration)
  self.alamofireManager!.request(.GET, "http://example.com/")
    .response { (request, response, data, error) in

    }
}
like image 145
user3786678 Avatar answered Oct 07 '22 22:10

user3786678