1

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!

1
  • 1
    Comment rather than answer since it's not really answering what you're looking for, but this: { (x, y) in x + y } is meant to be read as something like "a closure that takes as inputs the values for the variables x and y in the expression x + y", which is where the "in" comes from. Commented Sep 20, 2014 at 2:03

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.