적당한 고통은 희열이다

- 댄 브라운 '다빈치 코드' 중에서

Swift iOS 앱 개발/iOS

SceneDelegate에서 code base로 화면 진입점 설정하는 법

hongssup_ 2022. 11. 22. 11:13
반응형

스토리보드 없이 코드로 화면 진입점 설정하는 법

 

xcode 11 부터 멀티 윈도우를 지원하기 위해 SceneDelegate가 추가되었다. 

SceneDelegate 지우고 그냥 기존처럼 AppDelegate만 설정해줘도 되지만,

SceneDelegate에서 code base로 화면 진입점을 설정해보았다. 

방법은 비슷하다

 

1. Storyboard 삭제

2. Info.plist 에서 Storyboard Name 삭제

3. TARGETS - General - Deployment Info - Main Interface 에서 "Main" 지워주기

4. SceneDelegate에서 화면 진입점 설정

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        
    guard let windowScene = (scene as? UIWindowScene) else { return }
    window = UIWindow(windowScene: windowScene)
    window?.rootViewController = TabBarController()
    window?.backgroundColor = .systemBackground
    window?.makeKeyAndVisible()
}

 

Could not find a storyboard named 'Main' in bundle NSBundle 이라는 에러가 떴다. 

업데이트한 XCode에서는 저 위 3번 Main Interface 항목이 없다. 

TARGETS - Build Settings - Info.plist Values 에서 Main 을 지워주면 된다.

728x90
반응형