4
1

More than 1 year has passed since last update.

【Xcode14】Storyboardを削除してコードベースで開発する

Last updated at Posted at 2022-10-05

はじめに

以前Stroyboardを削除してコードのみで開発する方法の記事をあげましたが、Xcode14でやり方が変わっていたので紹介します。

Storyboardを削除

「Main」を右クリックして「Delete」を選択
スクリーンショット 2022-10-05 19.13.34.png
Move to Trashを選択
スクリーンショット 2022-05-17 0.46.52.png

Move to Trash Remove Reference
完全に削除 Xcodeの参照を削除

おそらくこんな感じの使い分けだと思います。

Infoを編集

Storyboard Nameを削除します。
① 「Info」を選択します
② 「Storyboard Name」を選択します
③ 「Storyboard Name」の「-」を押して削除します

スクリーンショット 2022-10-05 19.15.49.png

こうなります
スクリーンショット 2022-10-05 19.17.56.png

Mainの削除

① プロジェクトを選択します
② ターゲットを選択します
③ 「Info」を選択します
④ 「Main Storyboard file base name」を選択します
⑤ 「Main Storyboard file base name」の「-」を押して削除します
スクリーンショット 2022-10-05 19.19.53.png

こうなります
スクリーンショット 2022-10-05 19.23.35.png

SceneDelegateを編集

① 「SceneDelegate」を選択します
② 赤線で囲んである箇所を変更します
スクリーンショット 2022-10-05 19.28.03.png
これが完成形です
スクリーンショット 2022-10-05 19.29.47.png

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
-    guard let _ = (scene as? UIWindowScene) else { return }

+    if let windowScene = scene as? UIWindowScene {
+        let window = UIWindow(windowScene: windowScene)
+        window.rootViewController = ViewController()
+        self.window = window
+        window.makeKeyAndVisible()
+    }
}

完成

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
+       view.backgroundColor = .systemPink
    }


}

スクリーンショット 2022-10-05 19.33.05.png

おわり

XcodeでUIが変わっており見つけるのに苦労しました笑

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