What's an argument in Swift

What do $ 0 and $ 1 mean in Swift closures?

Swift 5

In your example and are the arguments of the first and second string in one. The short argument names are automatically provided by Swift. The first argument can be referenced with, the second argument with, the third by and so on.

As you know, a Closurethat one comes very close to the -Lambda function or one Small anonymous function is a stand-alone function block that can be passed along and used in your code. Closure has different names in other programming languages, as well as slight differences in meaning - it is Lambda in python and Kotlin or block in [~ # ~] c [~ # ~] and Objective-C .

Let's see how Closure works using short argument names:


1. Normal function

2. Closure Expression

3. Inline closure expression

4. Derive type from context

5. Implicit single-term closures returns

6. Short argument names

7. Operating methods


Without short argument names:

With short argument names:


The body of this clasp is short and easy to understand:

Hope that helps.