Is there a way to add a __attribute__((noescape)) to a parameter in Swift? I'm running into an issue with an Objective-C method that requires it.
In a large mixed project, I'm overriding UITableView.performBatchUpdates(_:completion) in a UITableView subclass in Swift.:
class MyCustomTableView: UITableView {
// how to annotate the updates parameter as NS_NOESCAPE?
public override func performBatchUpdates(_ updates: (() -> Void)?, completion: ((Bool) -> Void)? = nil) {
// do some bookkeeping
super.performBatchUpdates(updates, completion: completion)
}
}
This subclass is also used in the Objective-C parts of the project, so it get's added to the Project-Swift.h header and Swift automatically converts it to the following:
Swiss has this limitation: you can't have a closure non-escaping and optional at the same time, Optional<()->Void> is always escaping. With non optional closures (not your case) you just use @escaping to make the closure escaping and by default the closure is non escaping.
If you don't fear missing it in other possibly important cases, you may switch that warning off by adding -Wno-missing-noescape to Xcode's "Other Warning Flags".