问题
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?
回答1:
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 thein
keyword, even if you omit the parameter names, parameter types, and return type.
Example:
{
[weak arg1, weak arg2] in
// ...
}
来源:https://stackoverflow.com/questions/28015394/how-can-you-capture-multiple-arguments-weakly-in-a-swift-closure