iOS 프로젝트를 할 때 다른 개발자 분과 협업해야 하는 상황이 있었다. 다른 개발자 분과 나는 도메인을 나눠서 구현 범위를 정하기로 했는데, 여기서 문제는 Storyboard를 어떻게 나눠서 관리할지 정하는 것이었다.
도메인은 탭을 기준으로 확실하게 분리했다. 가령 나는 홈 화면, 지도 화면, 더보기 화면이라면 다른 개발자 분은 상태 화면, 일정 화면 이런 식으로 말이다. Storyboard도 이에 맞춰서 분리하기로 했다.
여기서 사용하게 된 것이 바로 Storyboard Reference.
Storyboard Reference란 무엇인지 살펴보자.
Storyboard Reference
Object Library에서 Storyboard Reference를 찾아봤다.
Storyboard references allow factoring storyboards into many files. Segues connected to the placeholders allow transitioning from one storyboard to another.
Storyboard reference는 Storyboard를 여러 개의 파일로 분리해서 사용할 수 있도록 한다. 플레이스홀더에 연결되어 있는 Segue(세그웨이)는 한 Storyboard에서 다른 Storyboard로 이동할 수 있도록 한다. 밑에 있는 그림을 살펴보자.
Segue(세그웨이)란? A segue defines a transition between two view controllers in your app’s storyboard file.
Storyboard 파일에서 두 개의 View Cotroller 사이의 이동을 정의하는 객체이다.

탭 별로 Storyboard 파일을 하나씩 만들고, Tab Bar View Controller가 있는 Storyboard 파일에서 Storyboard Reference를 사용했다.
Storyboard Reference를 왜 사용해야 해?
In bigger projects, the storyboard file can get crowded with many scenes. When working in a team, you’ll quickly learn that storyboard files can generate conflicts when more than one person is working on them.
But fear not, there is a remedy for that: Storyboard references. These allow you to break a storyboard into multiple files without losing any of the features illustrated so far.
출처: raywenderlich iOS Storyboards: Segues and More
여러 명이 하나의 Storyboard 파일을 두고 개발한다고 가정해보자. 동시에 한 파일을 접근하면서 파일 내 충돌이 생길 가능성이 매우 높다. 따라서 Storyboard 파일을 적당한 단위로 나눠 여러 개의 Storyboard 파일로 쪼개고, 각자 맡은 Storyboard에서 작업을 할 수 있다면 이러한 충돌 가능성을 피할 수 있다.
사용해보자
새로운 Storyboard 파일을 만든다. 이름은 SecondStoryboard로 했다.
연결하고 싶은 Storyboard 파일 내에서(여기선 Main Storyboard) Storyboard Reference를 놓고,
Inspector > Attributes inspector > Storyboard Reference > Storyboard에서 새롭게 만든 SecondStoryboard를 지정해준다.
Reference
- [raywenderlich] iOS Storyboards: Segues and More
- How to use storyboard references to simplify your storyboards
- 꼼꼼한 재은씨의 Swift: 기본편 (이재은 저)
'Development > iOS' 카테고리의 다른 글
[iOS] 화면 전환 (0) | 2021.12.20 |
---|---|
[iOS] UITabBarController (0) | 2021.12.17 |
[iOS] Cocoa Touch Framework (0) | 2021.12.13 |
[iOS] @IBSegueAction 사용해보기 (0) | 2021.09.08 |
[iOS] navigation hide back title (0) | 2021.09.02 |