KeyWindow issue

I am fixing a project created before iOS 13 and my Build fails due to the below line because "KeyWindow" is depreciated. Login and Signup ViewController swift files. I've googled endlessly for a solution of which I find a billion methods but don't see how to specifically fix this.

Code Block guard let mainTabBarController = UIApplication.shared.keyWindow?.rootViewController as? MainTabBarController else { return }


Help!

Answered by Claude31 in 631647022
You probably have to change as follows:

Code Block
       UIApplication.shared.keyWindow


with

Code Block
UIApplication.shared.windows[0]

That line is empty...

Show some code.
Accepted Answer
You probably have to change as follows:

Code Block
       UIApplication.shared.keyWindow


with

Code Block
UIApplication.shared.windows[0]


@KMT....didn't realize it was empty. Swore it was populated yesterday....here it is.

Code Block guard let mainTabBarController = UIApplication.shared.keyWindow?.rootViewController as? MainTabBarController else { return }




guard let mainTabBarController = UIApplication.shared.keyWindow?.rootViewController as? MainTabBarController else { return }

@KMT....can you see it this time.
@Claude31 That seems to have gotten rid of the errors. I cleaned the build folder and ran another build successfully.
Great. Thanks for the feed back and good continuation.

Don't forget to close the thread now.
KeyWindow issue
 
 
Q