Got this warning?
Here’s how to fix it with a clean one guard.
guard let scenes = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let rootViewController = scenes.keyWindow?.rootViewController else {
return
}
// use rootViewController and scenes as needed
or simplify it even further by doing this:
guard let rootViewController = (UIApplication.shared.connectedScenes.first as? UIWindowScene)?.keyWindow?.rootViewController else {
return
}
That’s it!