Bird
0
0

How would you declare a Swift function named calculate that takes an integer parameter without requiring an argument label when called?

easy📝 Syntax Q3 of 15
Swift - Functions
How would you declare a Swift function named calculate that takes an integer parameter without requiring an argument label when called?
Afunc calculate(number: Int) {}
Bfunc calculate(_ number: Int) {}
Cfunc calculate(number Int) {}
Dfunc calculate(_ number) {}
Step-by-Step Solution
Solution:
  1. Step 1: Syntax for omitting argument labels

    Use _ before the parameter name to omit the label.
  2. Step 2: Check each option

    func calculate(_ number: Int) {} correctly uses _ and specifies the parameter type.
  3. Final Answer:

    func calculate(_ number: Int) {} -> Option B
  4. Quick Check:

    Underscore before parameter name omits label [OK]
Quick Trick: Use underscore before parameter name to omit label [OK]
Common Mistakes:
  • Omitting the parameter type
  • Not using underscore to omit label
  • Incorrect parameter syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes