Swift
Xcode
Error Handling
Programming
Code Debugging

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

In Swift, function calls are part of the language's readability model, so parameter labels matter. The error "Missing argument label 'xxx' in call" means the function definition expects a labeled argument, but the call site omitted it or used the wrong label.

Why Swift uses argument labels

Swift separates the external label used at the call site from the internal parameter name used inside the function body. That makes calls read more like natural language.

For example:

swift
func greet(person name: String, from city: String) {
    print("Hello \(name) from \(city)")
}

The correct call is:

swift
greet(person: "Ava", from: "Toronto")

If you write this instead:

swift
greet("Ava", "Toronto")

Swift reports missing argument labels because the function requires person: and from:.

Reading the function signature correctly

The first identifier in a parameter can be the external label, and the second is the local name:

swift
func move(from source: String, to destination: String) {
    print("Move from \(source) to \(destination)")
}

At the call site:

swift
move(from: "A", to: "B")

If you omit one label or swap them, the compiler fails because the signature no longer matches.

How to intentionally remove a label

If you want a parameter to be unlabeled, use _ in the function definition:

swift
1func square(_ value: Int) -> Int {
2    value * value
3}
4
5let result = square(4)

Without the underscore, the function would require a label at the call site.

Initializers and methods follow the same rule

This error is not limited to free functions. It also appears with initializers and instance methods:

swift
1struct User {
2    let name: String
3    let age: Int
4}
5
6let user = User(name: "Ava", age: 30)

Calling User("Ava", 30) fails for the same reason: the synthesized initializer expects labeled arguments.

Methods behave the same way:

swift
1class Logger {
2    func log(message: String, level: String) {
3        print("[\(level)] \(message)")
4    }
5}
6
7let logger = Logger()
8logger.log(message: "Saved", level: "INFO")

How to debug the error quickly

When Xcode reports this error, jump to the function definition and compare the parameter list with the call site exactly. Do not guess. The fix is usually one of these:

  • add the missing label,
  • rename the label at the call site,
  • or change the definition to _ if the argument should be unlabeled.

Code completion is also useful because it inserts the expected labels automatically.

Common Pitfalls

The most common mistake is assuming the first parameter is unlabeled. In Swift methods and functions, that depends on the declaration, not on a universal rule you can memorize once.

Another issue is confusing parameter names with labels. In func greet(person name: String), person is the external label and name is the local variable inside the function.

Copying examples from older Swift versions can also be misleading because label behavior changed across major Swift releases. When in doubt, trust the current function signature shown by Xcode.

Finally, overloaded functions may require different labels even when they share a base name. If one overload takes at: and another takes from:, Swift treats them as different APIs.

This is why reading the generated function signature in Xcode is usually faster than reasoning from memory. The compiler is telling you exactly which external label the call site must use.

Summary

  • The error means the call site does not match the labels required by the function signature.
  • Swift uses argument labels to make calls clearer and safer.
  • Read the declaration carefully and match the external labels exactly.
  • Use _ in the declaration only when you intentionally want an unlabeled parameter.
  • The same label rules apply to functions, methods, and initializers.

Course illustration
Course illustration

All Rights Reserved.