What if you could make your function calls as simple as talking to a friend?
Why Omitting argument labels with _ in Swift? - Purpose & Use Cases
Imagine you have a function that takes many inputs, and every time you call it, you have to write the name of each input. It feels like filling out a long form repeatedly, even when the names are obvious.
Writing argument labels every time is slow and makes your code bulky. It's like repeating yourself over and over, which can cause mistakes and make your code harder to read.
By using _ to omit argument labels, you can call functions more simply and cleanly. It's like skipping unnecessary words in a conversation to get straight to the point.
func greet(person name: String) { print("Hello, \(name)!") }
greet(person: "Anna")func greet(_ name: String) { print("Hello, \(name)!") }
greet("Anna")This lets you write shorter, clearer function calls that feel natural and easy to read.
Think of a calculator app where you just enter numbers and operations quickly without typing extra labels every time.
Writing argument labels every time can be repetitive and clutter code.
Using _ lets you skip labels for simpler calls.
This makes your code cleaner and easier to read.