Bird
0
0

Identify the error in this Swift closure declaration:

medium📝 Debug Q6 of 15
iOS Swift - Swift Language Essentials
Identify the error in this Swift closure declaration:
let greet = { name: String in
  print("Hello, \(name)")
}
AClosure cannot have parameters
BMissing return type
CMissing parameter type parentheses
DIncorrect print syntax
Step-by-Step Solution
Solution:
  1. Step 1: Check closure parameter syntax

    Parameters must be enclosed in parentheses: (name: String)
  2. Step 2: Identify the error

    Code misses parentheses around parameter, causing syntax error.
  3. Final Answer:

    Missing parameter type parentheses -> Option C
  4. Quick Check:

    Closure parameters need parentheses [OK]
Quick Trick: Always wrap closure parameters in parentheses [OK]
Common Mistakes:
  • Omitting parentheses around parameters
  • Thinking return type is mandatory for void closures
  • Misusing print syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes