Bird
0
0

Which URLSession method initiates a network request that retrieves the contents of a URL asynchronously?

easy📝 Conceptual Q2 of 15
iOS Swift - Networking
Which URLSession method initiates a network request that retrieves the contents of a URL asynchronously?
AdownloadTask(with: URL)
BdataTask(with: URL)
CuploadTask(with: URL)
DstreamTask(with: URL)
Step-by-Step Solution
Solution:
  1. Step 1: Understand URLSession methods

    URLSession provides different task types: dataTask, downloadTask, uploadTask, and streamTask.
  2. Step 2: Identify the method for fetching data

    dataTask(with:) is used to fetch data asynchronously from a URL.
  3. Final Answer:

    dataTask(with: URL) -> Option B
  4. Quick Check:

    dataTask fetches data asynchronously [OK]
Quick Trick: Use dataTask to fetch data asynchronously [OK]
Common Mistakes:
  • Confusing downloadTask with dataTask
  • Using uploadTask for data retrieval
  • Assuming streamTask fetches data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes