Help us understand the problem. What is going on with this article?

Xcode11で作成したプロジェクトを古いOSに対応させる(とりあえず版)

Xcode11 beta で新規プロジェクトを作成。
001.png

Deployment Targetを古いOSに設定すると、
0002.jpg

エラーがぞろぞろ出てくるのをなんとかしようという話。
004.png


1. AppDelegate.swift と SceneDelegate.swift
エラーが出ている箇所に@availableを付ける。

AppDelegate.swift
// MARK: UISceneSession Lifecycle

@available(iOS 13.0, *)
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
  ()
}

@available(iOS 13.0, *)
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
  ()
}
SceneDelegate.swift
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {

2. AppDelegateにwindowプロパティを追加する。

AppDelegate.swift
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow? // 追加

とりあえず、これでエラーは出なくなります。

ただし、
(iOS 13)
1. 起動
2. AppDelegate application:didFinishLaunchingWithOptions: (windowはnil)
3. SceneDelegate scene:willConnectTo:options (windowに値がセットされる)

(iOS 12以下)
1. 起動
2. AppDelegate application:didFinishLaunchingWithOptions: (windowに値がセットされる)
3. SceneDelegate 呼ばれない

このような起動時の流れになりますので、windowプロパティにget / setしている場合はもうひと工夫必要になります。

Xcode11で作成したプロジェクトを古いOSに対応させる 完結編


Xcode 11 beta3を元に作成しています。後日変更される可能性があります。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした