관리 메뉴

김종권의 iOS 앱 개발 알아가기

[iOS - swift] 1. Storyboard로 UI 구현 기본기 - storyboard 장단점, Storyboard reference 개념 본문

iOS 응용 (swift)

[iOS - swift] 1. Storyboard로 UI 구현 기본기 - storyboard 장단점, Storyboard reference 개념

jake-kim 2023. 2. 28. 15:09

* Storyboard로 UI 구현 기본기 목차 참고

Storyboard 장단점

  • 장점
    • 처음오는 개발자도 한눈에 어떤 화면들이 있는지 파악이 용이
    • UI 관련 내용이 코드와 분리가 되어 코드의 복잡도가 줄어드는 점
  • 단점
    • 협업 시 merge conflict 해결이 어려움
    • Storybaord를 열기만 해도 수정사항이 생기므로 git add . 할 때 구분 필요
    • Storyboard에 여러개의 UIViewController가 많아지면 느려지는 문제
    • property들을 살펴볼 때 오른쪽 Attributes inspector를 통해 하나하나씩 확인해야 하므로 섬세하게 property들을 파악하기가 코드 베이스보단 힘든 점

Attributes Inspector

Storyboard Reference 개념

  • Storyboard안에서 reference를 두어서 다른 ViewController에 접근 할 수 있도록하는 방법
    • 같은 storyboard안에 ViewController를 다 넣지 않고 Storyboard를 분리하여 reference를 통해 접근하도록 사용

  • Storyboard Reference의 장점
    • 연결되어 있으므로 화면들의 추적(trace)이 용이
    • 파일이 분리되어 있기 때문에 재사용이 용이
    • merge conflict 문제 해결

https://developer.apple.com/documentation/technotes/tn3123-refactoring-your-storyboard

Storybord Reference 사용 방법

  • 아래 Tab Bar Controller안에 있는 UIViewController 2개를 별도의 storyboard 파일로 나누고 참조하도록 구현

storyboard reference 적용 전

  • 위 Storyboard에서 참조될 UIViewController를 위해, Storyboard 파일 2개 생성

  • 두 파일 각각 is initial View Controller 체크

  • Storyboard Reference를 사용하는 쪽 Tab Bar Controller에 옆에 있던 두 가지의 ViewController 삭제 및 Storyboard Reference 추가

  • Storyboard Reference를 선태갛고 Storyboard 항목에서 위에서 만든 First, Second 선택

  • Tab Bar Controller의 첫 번째 아이콘을 클릭한 후, Ctrl + 드래그를 하여 Storyboard Reference 와 연결

  • segue 타입은 view controllers 선택

  • 완성

  • Storyboard Reference를 왼쪽 마우스 더블 클릭하면 바로 이동하여, 개발자가 코드를 살펴볼때 trace(추적)이 매우 용이

더블 클릭하여 이동

정리

  • Storyboard Reference를 이용하면 Storyboard를 가지고 협업할때의 merge conflict 문제를 해결할 수 있음
  • Storyboard Reference를 사용하여 UI를 구현할 때, 하나의 UIViewController 당 하나의 Storyboard를 갖게끔하도록 ViewController를 분리할 것

* 참고

https://developer.apple.com/documentation/technotes/tn3123-refactoring-your-storyboard

Comments