⚔️

UIKitの最小構成(Main, LaunchScreen storyboardなし)

に公開
2026/05/19

構成

Storyboardなしの最小構成で、開発を進めていく構成です。

  • Main.storyboard無し
  • LaunchScreen.storyboard無し
  • AppDelegate有り
  • SceneDelegate有り

この記事で出来上がるアプリのスクショ

.pbxproj

INFOPLIST_KEY_UIMainStoryboardFileというキーが設定されていれば削除してください。
UI上だとUIKIt Main Storyboard File Base Nameという名前で表示されていると思います。

Info.plist

Lancu Screen -> Background Colorを設定する

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>UILaunchScreen</key>
  <dict>
    <key>UIColorName</key>
    <string>LaunchScreenBackground</string>
  </dict>
</dict>
</plist>

LaunchScreenBackgroundという名前でColor Assetを追加すると、それが起動時の色になります。

AppDelegate.swift

import UIKit

@main
final class AppDelegate: UIResponder, UIApplicationDelegate {
  func application(
    _ application: UIApplication,
    configurationForConnecting connectingSceneSession: UISceneSession,
    options: UIScene.ConnectionOptions
  ) -> UISceneConfiguration {
    let config = UISceneConfiguration(
      name: nil,
      sessionRole: connectingSceneSession.role
    )
    config.delegateClass = SceneDelegate.self
    return config
  }
}

SceneDelegate.swift

import UIKit

final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
  var window: UIWindow?

  func scene(
    _ scene: UIScene,
    willConnectTo session: UISceneSession,
    options connectionOptions: UIScene.ConnectionOptions
  ) {
    let windowScene = scene as! UIWindowScene
    let window = UIWindow(windowScene: windowScene)
    // ここでアプリのViewを設定
    window.rootViewController = UIHostingController(
      rootView: ContentView()
    )
    window.makeKeyAndVisible()
    self.window = window
  }
}

ContentView.swift

import SwiftUI

struct ContentView: View {
  var body: some View {
    NavigationStack {
      List {
        ForEach(0..<100) { i in
          Text("Cell \(i)")
       }
      }
      .navigationTitle("Title")
    }
  }  
}

Discussion