We have two broad patterns that we can use with the URLSession framework. One is very simple and will suffice for many situations, and the other requires a fair amount of additional coding, but offers us a much greater degree of control and flexibility.
Both patterns deal with asynchronous requests that will not block further execution of your code. Synchronous requests are not covered in this chapter, and you will quite possibly never need them.
The simplest set of calls to URLSession will involve passing a closure to whichever method we are calling. That closure must simply accept the correct arguments from the system when it gets called back. Once the download is complete, this closure will be populated with a response, some data, and an error, any of which may be nil
. Any code you need to run once the download finishes will go in this closure.