Codebased로 혼자 간단한 플젝을 진행하려고 하는데 codebased 해본 적이 없어 처음이라 엄청 설렌다 ㅎㅎ
codebased하려면 3가지 초기세팅이 필요한데, 잊지 않기 위해서 기록하려고 한다.
Build Settings에서 'UlKit Main Storyboard File Base Name'가 Main으로 설정되어 있는데, 이걸 지워야 한다.
변경 전
⬇️
변경 후
Info.plist에서 'Stroryboard Name' value를 Main으로 설정되어 있는데 이 또한 지워야 한다.
변경 전
⬇️
변경 후
SceneDelegate 파일의 scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) 함수 내부를 수정해야한다.
변경 전
// SceneDelegate.swift
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let _ = (scene as? UIWindowScene) else { return }
}
...
}
⬇️
변경 후
func scene(_ scene: UIScene,willConnectTo session: UISceneSession,options connectionOptions: UIScene.ConnectionOptions){
guard let windowScene = (scene as? UIWindowScene) else { return }
let window = UIWindow(windowScene: windowScene)
let mainViewController = MainViewController()
let navigationController = UINavigationController(rootViewController: mainViewController)
window.rootViewController = navigationController
self.window = window
window.makeKeyAndVisible()
}
window
의 rootViewController
에 할당한다. 나는 NavigationController를 사용할 것이므로 NavigationController 인스턴스를 rootViewController
로 설정하였다.