Junior — Middle
To which type of closures does an optional closure belong?
sobes.tech AI
Answer from AI
Optional closure in iOS is a closure that can be nil (i.e., absent). It pertains to the type of optional closures (Optional Closure).
This means that a variable or parameter containing a closure is declared using an optional type, for example:
var completionHandler: (() -> Void)?
Such a closure can only be called after checking for nil, which allows safe handling of the absence of an implementation.
Thus, an optional closure is a closure wrapped in an optional type, allowing it to either hold a closure or nil.