R

Ravina • 3.96K Points
Extraordinary

Q. What is the output of the following code?

Code:
var name: String? = "Swift"
if let unwrappedName = name {
print(unwrappedName)
}
  • (A) Optional("Swift")
  • (B) Swift
  • (C) unwrappedName
  • (D) nil
  • Correct Answer - Option(B)
  • Views: 23
  • Filed under category Swift (iOs)
  • Hashtags:

Explanation by: Ravina

Using `if let` unwraps the optional safely and prints the actual value, not the optional wrapper.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.