Functions and Closures
Argument Labels
Swift argument labels make function calls read like short phrases.
Name the call-site meaning
argument_labels.swift
func makeLabel(for item: String, count: Int) -> String {
return "\(item): \(count)"
}
let count =
let label = makeLabel(for: "tickets", count: count)
print(label)
func makeLabel(for item: String, count: Int) -> String {
return "\(item): \(count)"
}
let count =
let label = makeLabel(for: "tickets", count: count)
print(label)
func makeLabel(for item: String, count: Int) -> String {
return "\(item): \(count)"
}
let count =
let label = makeLabel(for: "tickets", count: count)
print(label)
labels
The external label appears at the call site, while the parameter name is used inside the function body.