Recently, I encountered a problem, which I have posted here, in stackoverflow. Apparently, the error was because a random UIWindow variable was used to display UI (and not the one in SceneDelegate).
Here's my understanding - Every time a scene is created (by user or the app), a UISceneSession is created to manage a UIScene, which can contain one or more UIWindows, each of which has views, which are displayed with the help of a view controller. Each UIScene will get a UISceneDelegate object to handle its lifecycle.
The error in my previous post makes sense now - since a random UIWindow object was used instead of the one in SceneDelegate.
But I still don't completely understand why a UIWindow was declared in the SceneDelegate by Xcode. There's a UIWindow object in UIWindowSceneDelegate (super class of my current SceneDelegate) and the documentation clearly explains that its a window associated with the scene. Why isn't that used and instead a new variable is created by Xcode while creating the project? If I need another window, then can I just add another UIWindow object to the current SceneDelegate? Is that a good practice?
@available (iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
// Remaining methods
}
I'm new to swift and iOS app development - any help to fill in these blanks would be greatly appreciated.