‘windows’ was deprecated in iOS 15.0に対処する

Xcode14での警告表示「’windows’ was deprecated in iOS 15.0: Use UIWindowScene.windows on a relevant window scene instead」の対処方法

元々のコードはRootViewControllerを取得するためのもの

let rootViewController = UIApplication.shared.windows.first?.rootViewController

これだとタイトルの非推奨警告が表示されますので下記のように修正

let scenes = UIApplication.shared.connectedScenes
let windowScene = scenes.first as? UIWindowScene
let root = windowScene?.windows.first?.rootViewController

これを少し短くすると下記のようになります

guard let scenes = UIApplication.shared.connectedScenes.first as? UIWindowScene ,
      let root = scenes.windows.first?.rootViewController else {
    return
}
//ここに処理

ifのを使用する場合

if let scenes = UIApplication.shared.connectedScenes.first as? UIWindowScene ,
   let root = scenes.windows.first?.rootViewController {
   //ここに処理
}

将来のために消せる警告文は消していきましょう!