LoginSignup
4
1

More than 1 year has passed since last update.

iOS15からの'windows' was deprecated in iOS 15.0: Use UIWindowScene.windows on a relevant window scene insteadに対応する

Last updated at Posted at 2022-01-06

はじめに

iOS15からUIApplication.shared.windowsを使用すると'windows' was deprecated in iOS 15.0: Use UIWindowScene.windows on a relevant window scene insteadという警告が発火します。

今回はこちらの警告の解消法を記事にします。

環境

Swift version 5.5
Xcode version 13.2.1

原因

iOS15から、windowsが非推奨になり,代わりに、UIWindowScene.windowsを使えといっています。

対処法

このように書けば警告を解消できます。

 let scenes = UIApplication.shared.connectedScenes
 let windowScenes = scenes.first as? UIWindowScene
 let window = windowScenes?.windows.first

rootViewControllerを定義したい場合は以下のように書けば動きます。

 let scenes = UIApplication.shared.connectedScenes
 let windowScenes = scenes.first as? UIWindowScene
 let rootVC = windowScenes?.keyWindow?.rootViewController

おわりに

ご覧いただきありがとうございました。
こうしたほうがいいや、ここはちょっと違うなど気になる箇所があった場合、ご教示いただけると幸いです。

おしらせ

現在、副業でiOSアプリ開発案件を募集しています!
全活動リンクをURLにまとめました。
https://linktr.ee/sasaki.ken

LinkTree_200×200.001.jpeg

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1