Optional or no-op callbacks?

by Cristián Arenas Ulloa

var callback: ((Int)->Void)? = nil


var callback: (Int)->Void = { _ in }


If your callback returns a value different from Void you can do more with the optional version:

callbackReturnsInt?(42) ?? 100

Most of the time it will be hard to find a good default value for a no-op callback.

Adrian Z.

Sign in to comment!