Using URLSession’s DelegateQueue for a better Quality of Service

Photo by Taylor Vick on Unsplash

OK, let’s jump straight in. You have a URLSession object, wether its a fully configured one, or the bare-bones, basic, shared singleton, either way you make your request, get your data and then go about your business…. and that’s great, but what if it wasn’t?

A simple, typical URLSession and data task.

I mean it’s not the end of the world, if we don’t specify a delegate Queue in iOS, one is created for us, with the default QoS set to .Background.

QOS (Quality of Service)

Apple defines 4 QoS Classes

  • User-interactive — If the work doesn’t happen quickly, the user interface may appear frozen.

Let’s turn up the heat, and specify a a DelegateQueue with a QoS of Utility in the URLSession initialiser, so any callbacks are scheduled in a more operation performant manner.

Operation Queue specified, with QoS of .Utility :)

It really is quite that simple, but remember, it’s our jobs as iOS developers to architect and implement our networking layer in such a manor that we don’t impact the UI and it’s responsiveness to the user. That would be pretty poor right?

Questions/thoughts/am I wrong? Leave me a comment.I’ve been doing iOS development now over 9 years commercially and I have never used Delegate Queue’s in URLSession, this post is to increase my knowledge and hopefully yours too.

Senior iOS Engineer  — Advanced Github downloader — Serial StackOverflow browser

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store