1. 記事の概要
XCodeを15.0にアップデート後、Main.StoryBoardを使わずにコードを実装しようとしたところ、若干ハマったので手順をまとめた
2. 実行環境
- 実行日: 2023年10月22日
カテゴリ | バージョン情報 |
---|---|
XCode | Version 15.0 beta 2 (15A5161b) |
Swift | Swift 5 |
3. 手順のまとめ(結論)
-
Info.Plist
の編集 -
Main.StoryBoard
を抹消 -
AppDelegate.swift
を編集
4. 手順
4-1. Info.Plistの編集
Info.Plist
内のBuild Settings
-> Info.plist Values
の中にあるUIKit Main StoryBoard File Base Name
にデフォルトでMain
が設定されているので削除
4-2. Main.StoryBoardを抹消
- プロジェクトナビゲータ内の
Main.StoryBoard
ファイルを右クリック->[Delete]を選択して抹消する
4-3. AppDelegate.swift
を編集
- AppDelegate.swift内の
didFinishLaunchingWithOptions
メソッドを以下のように書き換えます
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let rootVC = ViewController() // 起動時に表示したいViewController
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = rootVC
window?.makeKeyAndVisible()
return true
}
- sceneDelegate.swiftを編集する場合とAppDelegate.swiftを編集する方法がありますが、前者はここでは割愛します
5. 従来のバージョンとの変更点
- 従来のバージョンだとInfo.plistのStoryboard Nameを削除したり、Main Interfaceを削除しないといけなかったですが、XCode15.0からは若干シンプルになったように感じます