In Swift, escaping closure parameters are annotated with @escaping
. Is there any equivalent in Objective-C so that the generated Swift interfaces will be marked as @escaping
?
So what does an NS_NOESCAPE mean? (It's actually imported as @noescape .) It means that any argument that is passed inside this closure, which is void for void is not going to escape the runtime of the function itself.
In Swift, a closure marked with @escaping means the closure can outlive the scope of the block of code it is passed into. In a sense, @escaping tells the closure to “stay up even after the surrounding function is gone”.
In Swift, closures are non-escaping by default. This means that the closure can't outlive the function it was passed into as a parameter. If you need to hold onto that closure after the function it was passed into returns, you'll need to mark the closure with the keyword @escaping.
Yes, but it's backwards from what you suggest in your question. The rule is that an Objective-C nonnullable block is translated into Swift as an @escaping
function automatically, unless it is explicitly marked (NS_NOESCAPE ^)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With