Bird
0
0

Given this code:

hard📝 Application Q9 of 15
Swift - Optionals
Given this code:
var optionalString: String? = "Hello"
var implicitlyUnwrapped: String! = optionalString
print(implicitlyUnwrapped.uppercased())
What is the output?
ARuntime crash
BHELLO
COptional("HELLO")
DCompile error
Step-by-Step Solution
Solution:
  1. Step 1: Assign optional to IUO

    The optional optionalString has value "Hello" and is assigned to IUO implicitlyUnwrapped.
  2. Step 2: Access IUO property

    Accessing implicitlyUnwrapped.uppercased() unwraps IUO safely and returns "HELLO".
  3. Final Answer:

    HELLO -> Option B
  4. Quick Check:

    IUO unwraps optional value automatically = HELLO [OK]
Quick Trick: IUO unwraps optional value automatically when accessed [OK]
Common Mistakes:
  • Expecting Optional("HELLO") output
  • Assuming runtime crash
  • Thinking compile error due to assignment

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes