Bird
0
0

Identify the error in this Swift network call code:

medium📝 Debug Q6 of 15
iOS Swift - Networking
Identify the error in this Swift network call code:
URLSession.shared.dataTask(with: url) { data, response, error in
  if error != nil {
    print(error.localizedDescription)
  }
}.resume()
Aresume() is missing to start the task
Bdata parameter is not checked for nil
Cerror is optional and must be unwrapped before use
DURLSession.shared is incorrect usage
Step-by-Step Solution
Solution:
  1. Step 1: Check error usage

    error is an optional; accessing localizedDescription without unwrapping causes compile error.
  2. Step 2: Confirm resume() and other parts

    resume() is present; data check is optional; URLSession.shared is correct.
  3. Final Answer:

    error is optional and must be unwrapped before use -> Option C
  4. Quick Check:

    Optional error must be unwrapped = error is optional and must be unwrapped before use [OK]
Quick Trick: Always unwrap optional error before accessing properties [OK]
Common Mistakes:
  • Forgetting to unwrap error optional
  • Assuming resume() is missing
  • Confusing data nil check as error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes