I've come across this strange closure usage in the link
The below code is a simplified version in Xcode Playground
typealias AppStateDeeplinkAction = () -> ()
var deeplinkBlock : AppStateDeeplinkAction? = {
print ("this is for deeplink")
}
func deeplinkAction() {
if let deeplinkAction = deeplinkBlock {
print("deeplink is executed")
deeplinkAction() // <- if this is commented out, the result is just "deeplink is executed"
}
}
deeplinkAction()
The result of this is,
deeplink is executed
this is for deeplink
What's confusing is, deeplinkAction() func is called inside the if-let and there is no compile/run time error. It ended up successfully. What I don't get quite is the recursive call of deeplinkAction().
Compared to this, if deeplinkAction() is commented out, the result is just
deeplink is executed
What kind of 'closure' feature am I missing? How should I interpret this?