Bird
0
0

Why does Swift require explicit unwrapping of optionals instead of automatically unwrapping them?

hard📝 Conceptual Q10 of 15
Swift - Optionals
Why does Swift require explicit unwrapping of optionals instead of automatically unwrapping them?
ATo make code shorter and easier to write
BTo prevent unexpected nil values causing runtime crashes
CBecause Swift does not support nil values
DTo allow optionals to change type dynamically
Step-by-Step Solution
Solution:
  1. Step 1: Understand Swift's safety design

    Swift forces explicit unwrapping to avoid silent crashes from nil values.
  2. Step 2: Reason about automatic unwrapping

    Automatic unwrapping could hide bugs and cause unexpected crashes at runtime.
  3. Final Answer:

    To prevent unexpected nil values causing runtime crashes -> Option B
  4. Quick Check:

    Explicit unwrapping prevents crashes = A [OK]
Quick Trick: Explicit unwrapping avoids hidden nil crashes [OK]
Common Mistakes:
  • Thinking explicit unwrapping shortens code
  • Believing Swift disallows nil values
  • Assuming optionals change types dynamically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes