0
0
iOS Swiftmobile~5 mins

URLSession basics in iOS Swift - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Alaunch()
Bstart()
Cresume()
Dbegin()
What type of object does URLSession's dataTask(with:) method return?
AURLSessionDataTask
BURLRequest
CURLResponse
DData
Which parameter in the completion handler contains the downloaded data?
AURLResponse
BData
CError
DURLRequest
What happens if you forget to call resume() on a URLSessionDataTask?
AThe task completes instantly
BThe task runs automatically
CThe app crashes
DThe task never starts
Which class is responsible for managing network requests in iOS?
AURLSession
BUIViewController
CUIApplication
DURLRequest
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.