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:
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:
Fixed version:
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.
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.
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:
- Update signature in one place.
- Use IDE fix-its or rename refactor.
- Rebuild and resolve remaining call-site diagnostics.
- 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.
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 labelmeans 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.

