Max MacLeod
Max MacLeod

Reputation: 26652

Is There A Shorthand Syntax To Invoke An Optional Closure?

We know that in Swift we can do the following:

if myHandler = myOptionalHandler
{
   myHandler()
}

However, this seems a trifle long winded. Is there a shorter way?

Upvotes: 2

Views: 70

Answers (1)

Max MacLeod
Max MacLeod

Reputation: 26652

There is a shorter way! Simply execute the optional closure as follows:

myOptionalHandler?()

Upvotes: 2

Related Questions