본문 바로가기

All Categories/iOS & Swift

iOS 13+) Storyboard 없이 프로젝트 생성하기

반응형

안녕하세요 zhi재희입니다!

저는 최근에 이직하면서 🥳 Storyboard없이 SnapKit으로 UI 코드 작성하는 것에 익숙해지고 있답니다.

그래서 Storyboard없이 프로젝트를 생성하는 방법에 대해 알아보려고 합니다! 

 

1. 프로젝트 생성 

가장 먼저 새로운 프로젝트를 생성해 줍니다! 🎉

프로젝트 생성하기

기본적으로 이렇게 Main.storyboard가 존재하고 있습니다!

Project Navigator

 

2. Main.storyboard 삭제

과감하게 스토리보드를 삭제해줍니다!  그렇게 실행해보면?!

reason: 'Could not find a storyboard named 'Main' in bundle NSBundle

Main 스토리보드를 찾을 수 없다고 뜹니다!

 

3. 해결하기 - Info.plist

Info.plist 파일에서 2가지 row를 삭제해야 합니다.

1. Main storyboard file base name 을 찾아 삭제합니다

Main storyboard file base name

  1. Storyboard Name 을 찾아 삭제❌합니다

Storyboard Name

 

4. 초기 ViewController(Root) 지정 - SceneDelegate.swift

iOS 13부터 SceneDelegate에서 scene을 지정해 주어야 합니다! ✅

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

    var window: UIWindow?


    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        // guard let _ = (scene as? UIWindowScene) else { return } - 삭제
        guard let windowScene = (scene as? UIWindowScene) else { return }
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.windowScene = windowScene
        window?.rootViewController = ViewController()
        window?.makeKeyAndVisible()
    }

}

위 코드와 같이 window의 rootViewController를 지정해주면 끝입니다~!

ViewContoller의 배경 색상을 지정해서 잘 나오는지 확인해 봅시다!

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = .systemPink
    }

}

 

5. 마무리

짠! 

끝입니당 ㅎㅎ 수고하셨어용 😎

반응형