0

I want to send multiple HTTP requests (one after the other) in Swift using NSUrlSession, I am trying to login to a web page so I need to send a GET request and use the cookie for the following POST request and then use that authentication cookie to get the data I want from the site (a simple string from the response).

So I use this function call to send the request:

var task = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
    //Do stuff with response 
})
task.resume()

But I don't want to put tasks inside tasks clousure because what if I have 100 requests? I feel like there has to be another way but I could not find any example that uses more then a single request.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
reut
  • 21
  • 9
  • Dispatch a block to some queue (background?) from inside your block, to begin the next action. – David H Sep 29 '15 at 14:55
  • You might want to take a look at `NSOperation` and `NSOperationQueue`: http://www.raywenderlich.com/76341/use-nsoperation-nsoperationqueue-swift – Caio Sep 29 '15 at 16:17
  • Thank you , I will look at that ! – reut Sep 30 '15 at 11:07

0 Answers0