Trailing Closures

Similar to Swift, RemObjects C# supports using a Trailing Closures syntax when calling methods whose last parameter is a closure. This can make for code that looks cleaner and more easy to read than embedding the closure as last parameter within the parentheses.

The following snippet shows a call to dispatch_async with a trailing closure:

dispatch_async(dispatch_get_main_queue) {
    // do work

Compared to the classic call with the closure embedded:

dispatch_async(dispatch_get_main_queue, () => {
    // do work

If the closure receives any parameters, their names will be inferred from the declaration of the method or the delegate type used in the declaration, and become available as if they were local identifiers:


Trailing closures are not supported inside the base/this call to a deferred constructor, or inside __require/__ensure clauses.

See Also