In the context of pattern matching, x?
is the “optional pattern” and equivalent to .some(x)
. Consequently, case x??
is a “double optional pattern” and equivalent to .some(.some(x))
.
It is used here because UIApplication.shared.delegate?.window
evaluates to a “double optional” UIWindow??
, compare Why is main window of type double optional?.
Therefore
if case let presentationAnchor?? = UIApplication.shared.delegate?.window
matches the case that UIApplication.shared.delegate
is not nil and the delegate implements the (optional) window
property. In that case presentationAnchor
is bound to the “doubly unwrapped” UIWindow
.
See also Optional Pattern in the Swift reference:
An optional pattern matches values wrapped in a some(Wrapped)
case of an Optional<Wrapped>
enumeration. Optional patterns consist of an identifier pattern followed immediately by a question mark and appear in the same places as enumeration case patterns.