Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialShaan Marok
Courses Plus Student 1,015 PointsAssigning functions to variables in Swift
When we assign functions to variables in Swift, are the labels always omitted or is there a way to include them?
Example, for argument labels a and b
func sum(a: Int, b: Int) -> Int {
return a + b
}
let addTwoNumbers: (Int, Int) -> Int = sum
addTwoNumbers(1, 2)
1 Answer
Vansh Agarwal
Courses Plus Student 3,965 PointsYes, they are always omitted when you assign that function to a constant or variable. So if you call the function using the constant or variable name, there will be no argument labels as its type( the function signature ) does not include any argument labels. However if you call the function using the function name directly, there will be argument labels( if you have made labels ).
Jeff McDivitt
23,970 PointsJeff McDivitt
23,970 PointsThey are included you omit them with an underscore before the the variable