๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐ŸŽ iOS

[Swift] Storyboard ์—†์ด Swift ํ”„๋กœ์ ํŠธ ์‹œ์ž‘ํ•˜๊ธฐ

by ํ‹ด๋”” 2021. 3. 3.
๋ฐ˜์‘ํ˜•

Swift ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒˆ๋กœ ์ƒ์„ฑํ•˜๊ณ  ์‹คํ–‰ ์‹œํ‚ค๋ฉด ๊ธฐ๋ณธ์œผ๋กœ Main.storyboard๋ฅผ ์‹œ์ž‘์ ์œผ๋กœ ์žก๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ด๋•Œ ๋ฉ”์ธ ์Šคํ† ๋ฆฌ๋ณด๋“œ๋กœ ์‹œ์ž‘ํ•˜์ง€ ์•Š๊ณ  ์Šคํ† ๋ฆฌ๋ณด๋“œ ์—†์ด ํ”„๋กœ์ ํŠธ๋ฅผ ์‹คํ–‰์‹œํ‚ค๊ณ  ์‹ถ๋‹ค๋ฉด ์•„๋ž˜ ํŠœํ† ๋ฆฌ์–ผ ์ˆœ์œผ๋กœ ๋”ฐ๋ผ์„œ ์ง„ํ–‰ํ•ด ์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.


์šฐ์„  ํ”„๋กœ์ ํŠธ์— ์žˆ๋Š” Main.storyboard๋ฅผ ์‚ญ์ œํ•ด ์ค๋‹ˆ๋‹ค. ํ•ด๋‹น ํŒŒ์ผ์„ ํด๋ฆญํ•˜์‹œ๊ณ  ๋ฐฑ์ŠคํŽ˜์ด์Šค ๋ˆ„๋ฅด์‹œ๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ์ฐฝ์ด ๋œน๋‹ˆ๋‹ค. 

ํ•ด๋‹น ํŒŒ์ผ์˜ ์ฐธ์กฐ๋งŒ ์ง€์›Œ ์ค„ ๊ฒƒ์ธ์ง€ ์•„๋‹ˆ๋ฉด ํŒŒ์ผ์„ ํœด์ง€ํ†ต์œผ๋กœ ์˜ฎ๊ฒจ ์ฐธ์กฐ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ํŒŒ์ผ๋„ ๊ฐ™์ด ์ง€์›Œ ์ค„ ๊ฒƒ์ธ์ง€ ๋ฌป๋Š” ์ฐฝ์ž…๋‹ˆ๋‹ค. ์ด๋•Œ Move To Trash ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์„œ ์™„์ „ํžˆ ์‚ญ์ œ ํ•ด ์ค๋‹ˆ๋‹ค. Remove Reference๋Š” ์ฐธ์กฐ๋งŒ ์ง€์šฐ๋Š” ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— ํ•ด๋‹น ํ”„๋กœ์ ํŠธ์— ํŒŒ์ผ์ด ๋‚จ์•„ ์žˆ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ํŒŒ๋ž€ ๋ฒ„ํŠผ ๋ˆ„๋ฅด์ง€ ๋งˆ์‹œ๊ณ  ํšŒ์ƒ‰ ๋ฒ„ํŠผ ๋ˆŒ๋Ÿฌ ์ฃผ์„ธ์š”

 

๋‹ค์Œ์œผ๋กœ ํ”„๋กœ์ ํŠธ > ํƒ€๊นƒ > General ํƒญ์—์„œ Deployment Info๋ฅผ ๋ด…๋‹ˆ๋‹ค. Main Interface์˜ Main์„ ์ง€์›Œ์„œ ์œ„ ์‚ฌ์ง„๊ณผ ๊ฐ™์ด ์ง€์ •ํ•ด ์ค๋‹ˆ๋‹ค.

์ด์ œ info.plist๋กœ ํŒŒ์ผ์„ ํด๋ฆญํ•ด ์ค๋‹ˆ๋‹ค. ์‹คํ–‰ํ•ด ๋ณด๊ณ  Main์„ ์ฐพ์„ ์ˆ˜ ์—†๋‹ค๋Š” ๊ฒฝ๊ณ ์ฐฝ ํ™•์ธํ•˜๊ณ  ์ง€์›Œ๋„ ๋˜์ง€๋งŒ ๋จผ์ € ์‚ญ์ œํ•ด ์ฃผ๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ctrl + F ๋ˆŒ๋Ÿฌ์„œ main์„ ๊ฒ€์ƒ‰ํ•ด์„œ ์ฐพ์œผ์…”๋„ ๋˜๊ณ  Application Scene Manifest > Scene Configuration > Application Session Role > item 0 > Storyboard Name ์œผ๋กœ ํƒ€๊ณ  ๋“ค์–ด๊ฐ€์…”๋„ ๋ฉ๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์— ์Šคํ† ๋ฆฌ ๋ณด๋“œ๊ฐ€ Main์œผ๋กœ ์ง€์ •๋œ ๊ฒƒ์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ ์•ฑ ์‹คํ–‰์‹œ Main ์Šคํ† ๋ฆฌ๋ณด๋“œ๋ฅผ ์ฐธ์กฐํ•˜๋ฏ€๋กœ ํฌ๋ž˜์‹œ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ํ•ด๋‹น ํ–‰์„ ๋ˆ„๋ฅด๊ณ  ๋ฐฑ์ŠคํŽ˜์ด์Šค ํ‚ค๋ฅผ ๋ˆŒ๋Ÿฌ์„œ ์ง€์›Œ ์ค๋‹ˆ๋‹ค.

 

์ด์ œ ์œˆ๋„์šฐ๋ฅผ ์ง์ ‘ ์ง€์ •ํ•ด ์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค. main ์Šคํ† ๋ฆฌ๋ณด๋“œ๋กœ ์ง€์ • ๋ฌ์„ ๋•Œ๋Š” window๋ฅผ ์ž๋™์ ์œผ๋กœ ์ƒ์„ฑํ•ด ์ฃผ์ง€๋งŒ ์ง์ ‘ ์Šคํ† ๋ฆฌ๋ณด๋“œ ์—†์ด ํ”„๋กœ์ ํŠธ๋ฅผ ์‹คํ–‰ํ•˜๋ ค๋Š” ๊ฒฝ์šฐ RootView๋ฅผ ์„ค์ •ํ•ด ์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. 

project Navigator์—์„œ 

SceneDelegate๋ฅผ ์„ ํƒํ•ด ์ฃผ์„ธ์š”. SceneDelegate๊ฐ€ ๋‚˜์˜ค๊ธฐ ์ด์ „์—๋Š” AppDelegate์—์„œ ์ž‘์„ฑํ•ด ์ฃผ์—ˆ๋Š”๋ฐ ์•ฑ ์ƒ๋ช…์ฃผ๊ธฐ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•์ด iOS13 ๋ถ€ํ„ฐ ๋ฐ”๋€Œ์–ด์„œ SceneDelegate์—์„œ ์„ค์ •ํ•ด ์ฃผ์–ด์•ผ rootView๋ฅผ ์ง€์ •ํ•ด ์ค„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

    var window: UIWindow?


    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

        guard let windowScene = (scene as? UIWindowScene) else { return }
        
        window = UIWindow(frame: windowScene.coordinateSpace.bounds)
        window?.windowScene = windowScene
        window?.rootViewController = HomeViewController()
        window?.makeKeyAndVisible()
    }
}

ํ•ด๋‹น ํŒŒ์ผ์— window ํ”„๋กœํผํ‹ฐ๊ฐ€ ์žˆ๋Š” ๊ฒƒ ํ™•์ธํ•˜์‹œ๊ณ  ์œ„์™€ ๊ฐ™์ด ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด ์ค๋‹ˆ๋‹ค. ์œ„ ์ฝ”๋“œ์—์„œ HomeViewController ๋Š” ์ œ๊ฐ€ ์ƒ์„ฑํ•œ ํด๋ž˜์Šค์ด๋ฏ€๋กœ ์—ฌ๊ธฐ์— ์›ํ•˜์‹œ๋Š” ViewController ๋ฅผ ์ง€์ •ํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋ฉด ํ•ด๋‹น ViewController ๋กœ ์‹œ์ž‘ํ•˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


ํ‹€๋ฆฌ๊ฑฐ๋‚˜ ์ˆ˜์ •ํ•ด์•ผ ํ•  ๋ถ€๋ถ„์ด ์žˆ๋‹ค๋ฉด ์–ธ์ œ๋“ ์ง€ ๋Œ“๊ธ€๋กœ ์•Œ๋ ค์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๐Ÿ˜€


 

2023๋…„ ์ˆ˜์ •

Main storyboard file base name ์ด ํ•„๋“œ๋„ ์ง€์›Œ ์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค! ๋ฉ”์ธ ์Šคํ† ๋ฆฌ ๋ณด๋“œ ๋ชป ์ฐพ๋Š”  ์ด์Šˆ ๋– ์„œ ํ™•์ธํ•ด ๋ณด๋‹ˆ Main ์ด ์—ฌ๊ธฐ ์ €๊ธฐ ๋ฐ•ํ˜€ ์žˆ๋„ค์š” ใ… ใ…  ์ด ์ •๋„๋ฉด Main ์Šคํ† ๋ฆฌ๋ณด๋“œ ์“ฐ๋ผ๋Š” ์˜๋ฏธ๊ฐ€ ์•„๋‹ ๊นŒ?

 

 

 

// ์ฐธ๊ณ  ๋ธ”๋กœ๊ทธ์™€ ์‚ฌ์ดํŠธ

sarunw.com/posts/how-to-create-new-xcode-project-without-storyboard/

developer-fury.tistory.com/41

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€