iOS/UIKit

Setting up UIKit project without Storyboard (feat. Xcode 16)

TDCIAN 2024. 7. 27. 19:48

 

 

I prefer to make a UIKit project without storyboard when coding alone.

 

However, as the version of Xcode has been updated and the UI has changed,

the method of configuring UIKit project without Storyboard also changed.

 

Just follow these steps.

 

(1) Make a new project.

 

 

(2) Remove Main.storyboard without hesitation.

- Click 'Move to Trash'.

Click 'Move to Trash'!

 

(3) Move to Info.plist file, and dig into these step.

- Application Scene Manifest -> Scene Configuration -> Window Application Session Role -> Item 0 (Default Configuration) -> Storyboard Name

- Then you can find Main.

 

(4) Remove Main by clikcing '-(minus)' button.

 

(5) Move to project file, and click TARGETS(Not PROJECT), and click 'Info' tab.

- Then you can see 'Main storyboard file base name': Main

 

(6) Remove 'Main storyboard file base name' by clikcing '-(minus)' button.

 

(7) Now, open SceneDelegate.swift file

 

(8) Type these codes.

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

 

(9) Let's check ViewController.swift file

- As you see, I wrote 'self.view.backgroundColor = .systemYellow' to check this works propery.

- Now, it's time to build!

 

(10) Tada~ you nailed it! you made your project without Storyboard!

 

 

You can also check this project file on my GitHub.

https://github.com/TDCIAN/ProjectWithoutStoryboard