STOP Using $0 as a Shorthand Parameter in Swift

You need readable code!

Steven Curtis
3 min readMar 17, 2021
Photo by Sharon Mccutcheon on Unsplash

If you are using closures in your Swift code, you may become familiar with the shorthand parameter syntax. That is, parameter names are often represented as $0 or $1.

You may or may not be aware that these continue, in that for each parameter the shorthand name is incremented by one each time ($2 and $3 up to the number of arguments as is required in your code).

Why you should use shorthand parameters

Rather than having to think of parameter names, and making our code less easy to read as a result you might use shorthand parameters. The emphasis is on the might.

Why you should stop using shorthand parameters

Rather than making your code easier to read, you have developed code that obstruficates the meaning. That is, you have so many shorthand parameters that you are not sure which to choose.

So rather than stopping using $0, you are…

--

--

Responses (2)