Swift
programming
error handling
code debugging
Xcode

Missing argument label 'xxx' in call

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

The Swift compiler error Missing argument label appears when a function call does not match the labels declared in the function signature. Swift treats labels as part of the API contract, so a missing or wrong label is a compile-time failure. Once you understand how external and internal parameter names work, this error becomes easy to fix and prevent.

How Argument Labels Work in Swift

In Swift, each parameter can have two names:

  • External label used at the call site.
  • Internal name used inside the function body.

Example:

swift
1func sendEmail(to recipient: String, subject title: String) {
2    print("Sending to \(recipient) with subject \(title)")
3}
4
5sendEmail(to: "[email protected]", subject: "Welcome")

Here, to and subject are the external labels. The compiler expects them in the call. If you write sendEmail("[email protected]", "Welcome"), Swift reports a missing label error.

Labels improve readability by making intent clear at call sites. The tradeoff is stricter matching rules.

Why the Error Happens

The error usually appears in one of these situations:

  • You forgot a required label.
  • You changed a function signature but not all call sites.
  • You copied an example from older Swift syntax.
  • You expected Objective C style unlabeled first parameters in a custom API.

Simple failing example:

swift
1func move(from start: Int, to end: Int) {
2    print("\(start) -> \(end)")
3}
4
5move(1, 5)

Fixed version:

swift
move(from: 1, to: 5)

The compiler message can mention one specific label, but often both labels need review.

Using Underscore to Omit a Label

If you intentionally want no external label, use underscore in the declaration.

swift
1func multiply(_ a: Int, _ b: Int) -> Int {
2    a * b
3}
4
5let result = multiply(3, 4)
6print(result)

This is useful for mathematical or very common operations where labels would add noise. For business-domain APIs, explicit labels are usually clearer.

Initializers and Label Rules

Initializers follow similar rules. Custom initializers often require labels and trigger the same error when called incorrectly.

swift
1struct User {
2    let id: Int
3    let name: String
4
5    init(id: Int, name: String) {
6        self.id = id
7        self.name = name
8    }
9}
10
11let user = User(id: 42, name: "Ava")
12print(user)

If you write User(42, "Ava"), you get missing argument label errors because id and name are required.

Refactoring Safely

When you rename labels during refactoring, use Xcode rename tools instead of manual edits. Swift APIs are label-sensitive, so mechanical updates prevent partial migrations.

Good workflow:

  1. Update signature in one place.
  2. Use IDE fix-its or rename refactor.
  3. Rebuild and resolve remaining call-site diagnostics.
  4. Run tests to catch semantic mistakes after syntax fixes.

For public APIs, changing labels is source-breaking. Consider overloads or deprecation paths.

API Design Guidance

Choose labels that read like a sentence at call sites.

swift
1func scheduleMeeting(on date: String, with participant: String) {
2    print("Meeting on \(date) with \(participant)")
3}
4
5scheduleMeeting(on: "2026-03-10", with: "Team")

This style is easier to scan than unlabeled calls in large codebases.

Avoid over-labeling simple utility functions. Use underscore only when it improves clarity, not because it is easier to type.

Debugging Checklist

When you hit the error, run this quick check:

  • Inspect function declaration, not only call site.
  • Verify external labels in order.
  • Confirm overload target if multiple functions share the same base name.
  • Check if you are calling an initializer or method variant with different labels.
  • Accept fix-it only after reading the generated call.

This usually resolves the issue in minutes.

Common Pitfalls

  • Assuming labels are optional in Swift APIs. Fix by treating labels as part of function identity.
  • Using unlabeled calls after copying code from another language style. Fix by matching declared labels exactly.
  • Adding underscores everywhere to silence errors. Fix by designing labels intentionally for readability.
  • Renaming parameters in declarations without updating callers. Fix by using automated refactor tools.
  • Ignoring overload differences. Fix by checking full signatures, not just method names.

Summary

  • Missing argument label means the call site does not match declared external labels.
  • Swift labels are API contract elements, not cosmetic syntax.
  • Use underscore only when unlabeled calls improve clarity.
  • Refactor label changes with IDE tooling to avoid partial updates.
  • Strong label design prevents errors and improves call-site readability.

Course illustration
Course illustration

All Rights Reserved.