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?
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)
- User-interactive — If the work doesn’t happen quickly, the user interface may appear frozen.
- User-initiated — The work is required in order to continue user interaction.
- Utility — Work that may take some time to complete and doesn’t require an immediate result, such as downloading or importing data.
- Background — Work that operates in the background and isn’t visible to the user, such as indexing, synchronizing, and backups.
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.
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.