0
1

More than 1 year has passed since last update.

【SwiftUI】UIWindowを使うときの注意点

Posted at

はじめに

UIWindowをSwiftUIで使う際に落とし穴があるので記事にしておきます。

悪い例

let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene

良い例

let scene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene

悪い例を使うとどうなるか

iPadでクラッシュする

おわり

何が正解かわかりませんが、
もしかしたら、SceneDelegateから取得する方法が正しい方法かもしれません

0
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
0
1