Swift Academy · Lesson

Argument Labels and Parameter Names

External vs internal parameter names and how Swift's call-site reads like English.

Lesson 1 of 412 steps

Argument Labels and Parameter Names is a free Swift Academy lesson on CoddyKit. This is lesson 1 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, and your progress syncs across the web and the CoddyKit app. The Swift Academy course includes 4 lessons in total.

Welcome

Swift functions have two names for each parameter: an *external* argument label used at the call site, and an *internal* parameter name used inside the function body.

External vs Internal Names

```swift func greet(person name: String) { print("Hello, \(name)!") } greet(person: "Alice") // call site uses 'person' // body uses 'name' ``` The external label improves readability at the call site.

Omitting the External Label with _

Use `_` to suppress the argument label: ```swift func square(_ n: Int) -> Int { n * n } print(square(5)) // 25 — no label needed ``` Common for math and utility functions where the label would be redundant.

Matching the Label to English

Well-chosen labels make call sites read like sentences: ```swift func move(from source: String, to destination: String) {} move(from: "Home", to: "Work") ``` This is a core Swift API design principle.

Same External and Internal Name

When only one name is provided it serves as both: ```swift func add(a: Int, b: Int) -> Int { a + b } add(a: 3, b: 4) // label == parameter name ``` A common style for simple functions.

Multiple Parameters

```swift func divide(_ numerator: Double, by denominator: Double) -> Double { numerator / denominator } let result = divide(10.0, by: 2.0) // 5.0 ``` First parameter often has no label; subsequent ones have descriptive labels.

Parameter Labels in APIs

Apple's own APIs demonstrate this pattern: ```swift array.insert(42, at: 0) string.replacingOccurrences(of: "a", with: "b") URLSession.shared.dataTask(with: request) ``` Read each call site aloud — it should sound natural.

Overloading with Different Labels

Functions with the same name but different labels are distinct: ```swift func load(url: String) {} func load(file: String) {} load(url: "https://example.com") load(file: "/tmp/data.json") ``` Labels differentiate overloads without mangling the base name.

Nested Function Calls and Labels

Labels still apply when nested: ```swift func stringify(_ n: Int) -> String { "\(n)" } func print(line value: String) { print(value) } print(line: stringify(42)) // "42" ```

Best Practices

Guidelines: • Omit the first label when the function name implies it: `makeURL(string:)` → `makeURL("…")` • Use grammatical prepositions as external labels: `at`, `with`, `from`, `to` • Avoid labels that repeat type information: `func add(intValue v: Int)` is redundant

Quick Check

What symbol suppresses the external argument label at the call site?

Recap

Key takeaways: • `func f(external internal: Type)` — two names, external at call site • `_` suppresses the external label • Well-named labels make call sites read like English sentences • Same label and name when only one is provided Next: default and variadic parameters.
Free to start

Learn Swift with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
122
Lessons
409

Frequently Asked Questions

Is the “Argument Labels and Parameter Names” lesson free?

Yes — any 3 lessons of the Swift Academy learning path, including “Argument Labels and Parameter Names”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Swift Academy course includes 4 lessons in total.

What will I learn in “Argument Labels and Parameter Names”?

External vs internal parameter names and how Swift's call-site reads like English. You practise Swift Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Swift Academy?

No prior experience is required. Swift Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.

How long does the “Argument Labels and Parameter Names” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Swift Academy lesson?

Yes. Every Swift Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Argument Labels and Parameter Names
  2. Default and Variadic Parameters
  3. In-Out Parameters and Multiple Returns
  4. Functions as First-Class Values
← Back to Swift Academy