Bird
0
0

Identify the error in this Swift code snippet for navigation:

medium📝 Debug Q6 of 15
iOS Swift - Navigation
Identify the error in this Swift code snippet for navigation:
navigationController?.popViewController(animated: "true")
AThe animated parameter should be a Boolean, not a String
BpopViewController does not accept any parameters
CnavigationController is not optional and should not use ?
DThe method name is incorrect; it should be popController()
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter type

    The animated parameter expects a Boolean value, but "true" is a String.
  2. Step 2: Verify method signature

    popViewController(animated:) accepts a Bool, so passing a String causes a type error.
  3. Final Answer:

    The animated parameter should be a Boolean, not a String -> Option A
  4. Quick Check:

    Animated parameter type = Bool, not String [OK]
Quick Trick: Animated parameter must be true or false, not "true" [OK]
Common Mistakes:
  • Passing string instead of Boolean
  • Misnaming the method
  • Misusing optional chaining

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes