Recall & Review
beginner
What is URLSession used for in iOS development?
URLSession is used to make network requests, like downloading data from the internet or sending data to a server.
Click to reveal answer
beginner
What method of URLSession is commonly used to start a simple data task?
The
dataTask(with:completionHandler:) method is used to start a task that fetches data from a URL.Click to reveal answer
beginner
Why do we call
resume() on a URLSessionDataTask?Calling
resume() starts the network request. Without it, the task stays suspended and does nothing.Click to reveal answer
intermediate
What parameters does the completion handler of a URLSession data task provide?
It provides
Data? (the response data), URLResponse? (info about the response), and Error? (any error that happened).Click to reveal answer
intermediate
How can you handle errors when using URLSession?
Check if the
Error? parameter in the completion handler is not nil, and handle it by showing a message or retrying.Click to reveal answer
Which method starts a URLSession data task?
✗ Incorrect
You must call resume() on the data task to start it.
What type of object does URLSession's dataTask(with:) method return?
✗ Incorrect
dataTask(with:) returns a URLSessionDataTask object.
Which parameter in the completion handler contains the downloaded data?
✗ Incorrect
The Data? parameter contains the downloaded data.
What happens if you forget to call resume() on a URLSessionDataTask?
✗ Incorrect
Without resume(), the task stays suspended and does not start.
Which class is responsible for managing network requests in iOS?
✗ Incorrect
URLSession manages network requests like downloading or uploading data.
Explain how to create and start a simple URLSession data task to fetch data from a URL.
Think about the steps from making the request to getting the response.
You got /4 concepts.
Describe the role of the completion handler in a URLSession data task.
What do you do after the network call finishes?
You got /4 concepts.