How to fix deprecated 'keyWindow' in iOS 13 and above (Swift)
Hello everyone! I'm a beginner iOS developer writing an app in Swift. I recently updated Xcode to version 12, and my project stopped compiling. I'm using the old way to get the main window of the app via `UIApplication.shared.keyWindow`, but the compiler gives a warning: `'keyWindow' was deprecated in iOS 13.0`. Here's my code:
```swift
if let keyWindow = UIApplication.shared.keyWindow {
// Trying to show some controller on top of everything
let alert = UIAlertController(title: "Error", message: "Something went wrong", preferredStyle: .alert)
keyWindow.rootViewController?.present(alert, animated: true)
}
```
I understand that Apple changed something in iOS 13 with multitasking and scenes (UIScene), but I can't figure out how to properly get the window now. I tried