Multiple http requests [iOS Apprentice 4]

I’ve just completed iOS Apprentice 4 and have a quick question to continue to the next step. :wink:

Can an app share the same session(NSURLSession.sharedSession()) and its completionHandler to interact with and handle multiple URLs?
Are there any best practices to work with multiple URLs?

Many thanks in advance for any feedbacks.

Yes, multiple http requests can use the same session. Each request gets its own data task object. If the requests are very different (i.e. they expect different responses from the server), then each will also get its own completion handler.

1 Like

Thank you very much for your prompt update!
I’ll try more complex application by maximising what I learned through a series of 4 iOS Apprentice books! :smile:

Hello again!

May be this is beyond the forum but I’d appreciate it if anybody would give me a pointer. :slight_smile:

I think this is a design issue but I would like to know its feasibility because my app is not working so far.
The question is if I can make 2nd async http call within the scope of the completion handler of 1st http async call.
Is it possible or a bad design pattern?

Looks like my app is getting lost.
SO, I would like to learn if it’s feasible before I dig into and spend more hours.

Many thanks in advance for your help.

It is possible, but the second request will run after the first one has completed, not at the same time. The principle is the same as doing a single request, really.

1 Like