In my app I want to create a new UIWindow
over the main UIWindow, And I wrote as following, but it don\'t works.
first, i create a UIWindow
as the
Your window1
object is a local variable, when the code runs out of this method, this object does not exist any more. Any UIWindow
object we created will be add to the [[UIApplication sharedApplication] windows]
, but this array only keep a week reference to any UIWindow
object, so it's up to your own code to keep the window object exist.Why apple achieved like this, I guess, is [UIApplication sharedApplication]
object exists as long as the app runs, doing so to avoid keeping the UIWindow
objects which only need to be exist for a while living in the memory "forever".
What's more, your code could run with MRC.
if you just need to change shared window ViewController in swift 5
UIApplication.shared.keyWindow?.rootViewController = UINavigationController(rootViewController: yourViewController)