Properties2
| Type | Concept |
| Note created | Feb 17, 2025 |
Swift provides a shorthand syntax when passing a closure to a function. The syntax is the simpler when the function accepts a single function:
func stuff(f: () -> Void) {
// ...
}
// Regular syntax
stuff(by: { print("Hello!") })
// Trailing shorthand
stuff { print("Hello!") }The syntax is a bit more complicated when there are multiple functions being accepted:
func complicatedStuff(first: () -> Void, second: () -> Void, third: () -> Void) {
// ...
}
complicatedStuff {
print("First!")
} second: {
print("Second!")
} third: {
print("Third!")
}