Overview - Omitting argument labels with _
What is it?
In Swift, functions often have argument labels to clarify what each parameter means when calling the function. Sometimes, you want to skip writing these labels when calling the function for simplicity or readability. Using an underscore (_) before a parameter name tells Swift to omit the argument label when calling the function. This means you just pass the value directly without naming it.
Why it matters
Argument labels help make code clearer, but sometimes they can be verbose or unnecessary. Omitting them with _ lets you write cleaner, shorter calls when the meaning is obvious. Without this feature, Swift code could become cluttered with repetitive labels, making it harder to read and write, especially for simple functions or those with common parameters.
Where it fits
Before learning this, you should understand basic Swift functions and how argument labels work. After this, you can explore advanced function features like default parameters, variadic parameters, and function overloading to write flexible and expressive Swift code.