let actionSheet = UIAlertController(title: "選択", message: nil, preferredStyle: .actionSheet) actionSheet.addAction(UIAlertAction(title: "1つめ", style: .default) { _ in // なんとかかんとか }) actionSheet.addAction(UIAlertAction(title: "2つめ", style: .default) { _ in // なんとかかんとか }) actionSheet.addAction(UIAlertAction(title: "キャンセル", style: .cancel)) UIApplication.shared.windows.first?.rootViewController?.present(actionSheet, animated: true)
というコード書いたら
'windows' was deprecated in iOS 15.0: Use UIWindowScene.windows on a relevant window scene instead
で非推奨の警告が・・
以下に置き換えた
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene, let window = windowScene.windows.first, let rootViewController = window.rootViewController { rootViewController.present(actionSheet, animated: true, completion: nil) }