Beginning Networking with URLSession, Episode 7: Challenge: Fetch Data Over the Network | Kodeco

In this challenge episode you will put your existing knowledge about URLSession to the test in order to download and display data downloaded from the network.

This is a companion discussion topic for the original entry at

Do you need to wrap the url request in a Task? I didn’t do it and it worked just fine

Do you have a snippet of your usage compared to this episode? Without that bit of context it might not be an accurate answer to your question :slight_smile:

Hope you’re enjoying the course!

fetchMusic() is already called in a Task. I also wonder whether wrapping url) in a Task is necessary.

Hello :slight_smile:

Regarding your question, about wrapping url) in a task I imagine you are referring to the solved challenge.

In this scenario, using Task within the function may not be strictly necessary as the calling context already calls it in a task. If you were to call this method elsewhere, however, it could be beneficial to do so in a task within the function, but there’s no one-size-fits-all solution.

As for how we call the function within the button’s action, if I recall correctly Task is used there in order to avoid a compiler error about calling an async function in a non-concurrent fashion.


1 Like