Consider the following code block
// self is a UIViewController
let f = self.view.window?.rootViewController?.view.frame
Here f is an Optional wrapping CGRect. As far as I can understand,
- view is implicitly unwrapped property.(i.e. UIView!).
- We access the window property of it with optionally unwrapping the optional window property of view. If it has value then access its rootViewController property else do nothing.
Similarly we optionally unwrap rootViewController and access its view property.
Finally we get frame of view.
Since any of the window or rootViewController can be nil, frame is an Optional.
Am I understanding it correctly. Also why the view property of UIViewcontroller is optional?
view
of this:rootViewController?.view
? – Bista