lpappone
lpappone

Reputation: 2755

What is the meaning of "in" in Swift?

I'm learning Swift, and want to make sure I know what each part of my code does, even if it works. I can't figure out precisely what "in" does here, even though the function breaks if I remove it.

session.dataTaskWithRequest(request) { (data, response, error) in
...

The rest of the code isn't really relevant - just wondering what "in" does.

Thanks!

Upvotes: 1

Views: 99

Answers (2)

Connor
Connor

Reputation: 64644

It is part of swift's closure syntax. Because the parameters and a return type of a closure are inside the curly braces in is used to separate them from the body.

Upvotes: 1

Allen Zeng
Allen Zeng

Reputation: 2665

Go read the book, it's all in there:

Use in to separate the arguments and return type from the body.

Upvotes: 1

Related Questions