Swift - External Parameter Names Shorthand

Introduction

The local parameter name itself can be descriptive enough to be used as an external parameter name.

Consider the previous example:

func myFunction(num1: Int, num2: Int) {
     print(num1, num2)
}

To use num1 as the external parameter name for the first parameter and num2 for the second parameter.

You could write it as follows:

func myFunction( num1  num1: Int, num2  num2: Int) {
}

Instead of repeating the parameter names twice, you could use the shorthand #, like this:

func myFunction( # num1: Int, # num2: Int) {
}

To call the function, you specify the external parameter names like this:

myFunction(num1 :5, num2 :6)

Related Topic