Before we all get used to the approach when in AppDelegate
we create UIWindow
and then set rootViewController
for this Window
. Sometimes when we needed to have a custom alert we can create a new UIWindow
that will be above.
Now Xcode automatically creates UIScene
and creates UIWindow
base on this scene. I would appreciate if somebody can explain in details how to use this scenes in real life and what is their major benefit from using just UIWindow
in AppDelegate
Because this article doesn't explain much
An object that represents one instance of your app's user interface.
The UIApplication class defines a delegate that conforms to the UIApplicationDelegate protocol and must implement some of the protocol's methods.
The scene is a part of an app's user interface with a lifecycle managed by the system. The system will decide how to present it to a user depending on the running platform.
Windows work with your view controllers to handle events and to perform many other tasks that are fundamental to your app's operation. UIKit handles most window-related interactions, working with other objects as needed to implement many app behaviors.
You should read the App and Environment Article from Apple instead of UIScene
documentation.
As it says about the scenes:
Scene, Manage multiple instances of your app’s UI simultaneously, and direct resources to the appropriate instance of your UI.
We had only one scene back then before iOS 13, So the only thing we need to run ViewController
s simultaneously was multiple Window
s on top of each other. But now, each application can have multiple instances running at the same time! Each scene has its own state and it might be in the foreground while others are in the background or are suspended, while Window
was completely depended on the application itself.
Imagine we have 2 view controllers (consider there are no scenes) running on the left and right side of the device and then we need to show a banner. Using the old window method will show the banner on both of them! And if you need to pick one, you may end up finding the correct controller and presenting the banner on it, (I think all of us done this method before getting familiar with UIWindow
)
So apple introduced Scene
, a container for each separate instance of the app. So you can manage each one separately and each of them acts like a separate app. It has its own window
s and controller
s. But all of them are managed by a single object, UIApplication.shared
and it has a delegate
to handle general events (usually from outside of the app) and entire application life cycle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With