はじめに
ストーリーボードを使わないアプリの設定方法を忘れてしまうので忘備録を作成
環境
Xcode Version 12.5.1 (12E507)
手順
1.アプリのDeployment Infoの設定
Main Interfaceの”Main”の文字を削除
2.Info.plistのApplication Scene Manifestを項目ごと削除
選択して項目ごと削除
3.不要なファイルの削除
SceneDelegate.swiftとMain.Storyboardは使わないので左のNavigatorから削除
※SceneDelegate.swiftは全文コメントアウトでも可
4.AppDelegate.swiftの編集
AppDelegate.swift
import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
//①プロパティを宣言
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
//②ViewControllerのClassをrootViewControllerに設定して表示する
let window = UIWindow(frame: UIScreen.main.bounds)
self.window = window
window.makeKeyAndVisible()
window.rootViewController = ViewController()
//NavigationBarを使う場合
//window.rootViewController = UINavigationController(rootViewController: ViewController())
return true
}
// MARK: UISceneSession Lifecycle
//③ 初めからある以下2つのメソッドをコメントアウト
//
// func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// // Called when a new scene session is being created.
// // Use this method to select a configuration to create the new scene with.
// return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
// }
//
// func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// // Called when the user discards a scene session.
// // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
// }
}
上記のように編集
①windowプロパティの宣言
②ViewControllerのClassをrootViewControllerに設定して表示する
③2つのメソッドをコメントアウト
参考にさせていただきました