1

The Swift compiler complains about

let insets : UIEdgeInsets? = UIApplication.shared.delegate?.window?.safeAreaInsets

with the error message

Value of optional type UIWindow? must be unwrapped to refer to member safeAreaInsets of wrapped base type UIWIndow. Chain the optional using '?' to access member safeAreaInsets only for non-nil base values.

The code

let insets : UIEdgeInsets? = UIApplication.shared.delegate?.window??.safeAreaInsets

works fine. Why is the second question mark after window required? The two question marks here do not seem to constitute the nil-coalescing operator. I'm obviously missing something.

  • 2
    Possible duplicate of: [Why is main window of type double optional?](https://stackoverflow.com/questions/28901893/why-is-main-window-of-type-double-optional) – TylerP Sep 08 '21 at 00:10

0 Answers0