Bird
0
0

Which operator in Swift safely unwraps an optional and provides a default value if nil?

easy📝 Conceptual Q2 of 15
Swift - Operators and Expressions
Which operator in Swift safely unwraps an optional and provides a default value if nil?
A->
B!
C??
D?.
Step-by-Step Solution
Solution:
  1. Step 1: Identify the operator that provides a default

    The ?? operator unwraps an optional or returns a default if nil.
  2. Step 2: Differentiate from other operators

    ! force unwraps (unsafe), ?. safely accesses properties, -> is for function return types.
  3. Final Answer:

    ?? -> Option C
  4. Quick Check:

    Default value operator = ?? [OK]
Quick Trick: Use ?? to provide defaults for nil optionals [OK]
Common Mistakes:
  • Using ! which can crash if nil
  • Confusing ?. with ??
  • Thinking -> unwraps optionals

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes