0Pricing
Swift Academy · Lesson

Argument Labels and Parameter Names

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

Argument Labels and Parameter Names is a free Swift Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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.

Frequently asked questions

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

Yes — the full text of “Argument Labels and Parameter Names” is free to read here on the web, and the Swift Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Swift Academy course, upgrade to CoddyKit PRO.

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; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

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