42

Is there a way to capture multiple arguments weakly in a swift closure? I know this is the syntax to capture one argument weakly:

{ [weak arg]
    arg.doSomething()
}

How can I do this for two objects that I wish to capture weakly?

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
phoganuci
  • 4,984
  • 9
  • 39
  • 50

1 Answers1

106

From Expressions in "The Swift Programming Language" (emphasis added):

Closure Expression
...
A closure expression can explicitly specify the values that it captures from the surrounding scope using a capture list. A capture list is written as a comma separated list surrounded by square brackets, before the list of parameters. If you use a capture list, you must also use the in keyword, even if you omit the parameter names, parameter types, and return type.

Example:

{
    [weak arg1, weak arg2] in 
    // ...
}
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382