Notice
Recent Posts
Recent Comments
Link
관리 메뉴

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

[iOS - Swift] 1. Tuist로 모듈화하기 - 이미 존재하는 프로젝트에 적용 방법 본문

iOS 응용 (swift)

[iOS - Swift] 1. Tuist로 모듈화하기 - 이미 존재하는 프로젝트에 적용 방법

jake-kim 2022. 12. 14. 23:21

* 최신 Tuist 내용은 이 포스팅 글 참고


1. Tuist로 모듈화하기 - 이미 존재하는 프로젝트에 적용 방법 <

2. Tuist로 모듈화하기 - 기본 개념 (Dynamic Framework, Static Framework, Mach-O)

3. Tuist로 모듈화하기 - Tuist로 프로젝트 구성 방법 (의존성 관리, 프로젝트 구조 설정)

모듈

  • 프로젝트 구조 파악 - 프로젝트 루트 경로로 이동 후 아래 명령어 실행
    • tree 설치가 안되어 있다면 설치: brew install tree
% tree .
  • Xcode로 프로젝트 처음 만들었을때 구조
% tree .
.
├── Jake
│   ├── AppDelegate.swift
│   ├── Assets.xcassets
│   │   ├── AccentColor.colorset
│   │   │   └── Contents.json
│   │   ├── AppIcon.appiconset
│   │   │   └── Contents.json
│   │   └── Contents.json
│   ├── Base.lproj
│   │   ├── LaunchScreen.storyboard
│   │   └── Main.storyboard
│   ├── Info.plist
│   ├── SceneDelegate.swift
│   └── ViewController.swift
└── Jake.xcodeproj
    ├── project.pbxproj
    ├── project.xcworkspace
    │   ├── contents.xcworkspacedata
    │   ├── xcshareddata
    │   │   ├── IDEWorkspaceChecks.plist
    │   │   └── swiftpm
    │   │       └── configuration
    │   └── xcuserdata
    │       └── gimjong-gwon.xcuserdatad
    │           └── UserInterfaceState.xcuserstate
    └── xcuserdata
        └── gimjong-gwon.xcuserdatad
            └── xcschemes
                └── xcschememanagement.plist

15 directories, 14 files

tuist로 모듈화 목표

* tuist에 관한 구체적인 내용은 이전 포스팅 글 참고

모듈화의 장점

  • 빌드 속도 향상 (모듈화로 나누어져 있으면, 빌드 시 변경된 부분만 빌드)
  • 결합도 감소, 응집도 증가
  • .pbxproj에 UUID의 conflict를 줄일 수 있는 장점

비포 & 에프터

  • before
.
├── Derived
│   └── InfoPlists
│       └── Jake-Info.plist
├── Jake
│   ├── AppDelegate.swift
│   ├── Assets.xcassets
│   │   ├── AccentColor.colorset
│   │   │   └── Contents.json
│   │   ├── AppIcon.appiconset
│   │   │   └── Contents.json
│   │   └── Contents.json
│   ├── Base.lproj
│   │   ├── LaunchScreen.storyboard
│   │   └── Main.storyboard
│   ├── Info.plist
│   ├── SceneDelegate.swift
│   └── ViewController.swift
├── Jake.xcodeproj
│   ├── project.pbxproj
│   ├── project.xcworkspace
│   │   ├── contents.xcworkspacedata
│   │   ├── xcshareddata
│   │   │   ├── IDEWorkspaceChecks.plist
│   │   │   └── swiftpm
│   │   │       └── configuration
│   │   └── xcuserdata
│   │       └── gimjong-gwon.xcuserdatad
│   │           └── UserInterfaceState.xcuserstate
│   ├── xcshareddata
│   │   ├── xcdebugger
│   │   └── xcschemes
│   │       ├── Jake-Debug.xcscheme
│   │       ├── Jake-Release.xcscheme
│   │       └── Jake.xcscheme
│   └── xcuserdata
│       └── gimjong-gwon.xcuserdatad
│           └── xcschemes
│               └── xcschememanagement.plist
├── Jake.xcworkspace
│   ├── contents.xcworkspacedata
│   ├── xcshareddata
│   │   ├── IDEWorkspaceChecks.plist
│   │   ├── WorkspaceSettings.xcsettings
│   │   ├── swiftpm
│   │   │   └── configuration
│   │   └── xcschemes
│   │       └── Jake-Workspace.xcscheme
│   └── xcuserdata
│       └── gimjong-gwon.xcuserdatad
│           ├── UserInterfaceState.xcuserstate
│           └── xcschemes
│               └── xcschememanagement.plist
└── Project.swift
  • after
.
├── Derived
│   └── InfoPlists
│       └── Jake-Info.plist
├── Jake
│   ├── AppDelegate.swift
│   ├── Assets.xcassets
│   │   ├── AccentColor.colorset
│   │   │   └── Contents.json
│   │   ├── AppIcon.appiconset
│   │   │   └── Contents.json
│   │   └── Contents.json
│   ├── Base.lproj
│   │   ├── LaunchScreen.storyboard
│   │   └── Main.storyboard
│   ├── Info.plist
│   ├── SceneDelegate.swift
│   └── ViewController.swift
├── Jake.xcodeproj
│   ├── project.pbxproj
│   ├── project.xcworkspace
│   │   ├── contents.xcworkspacedata
│   │   ├── xcshareddata
│   │   │   ├── IDEWorkspaceChecks.plist
│   │   │   └── swiftpm
│   │   │       └── configuration
│   │   └── xcuserdata
│   │       └── gimjong-gwon.xcuserdatad
│   │           └── UserInterfaceState.xcuserstate
│   ├── xcshareddata
│   │   ├── xcdebugger
│   │   └── xcschemes
│   │       ├── Jake-Debug.xcscheme
│   │       ├── Jake-Release.xcscheme
│   │       └── Jake.xcscheme
│   └── xcuserdata
│       └── gimjong-gwon.xcuserdatad
│           └── xcschemes
│               └── xcschememanagement.plist
├── Jake.xcworkspace
│   ├── contents.xcworkspacedata
│   ├── xcshareddata
│   │   ├── IDEWorkspaceChecks.plist
│   │   ├── WorkspaceSettings.xcsettings
│   │   ├── swiftpm
│   │   │   └── configuration
│   │   └── xcschemes
│   │       └── Jake-Workspace.xcscheme
│   └── xcuserdata
│       └── gimjong-gwon.xcuserdatad
│           ├── UserInterfaceState.xcuserstate
│           └── xcschemes
│               └── xcschememanagement.plist
└── Project.swift

Tuist로 모듈화하기

  • tuist 설치
curl -Ls https://install.tuist.io | bash
  • 프로젝트가 이미 만들어져 있는 경우, Project.swift 파일을 프로젝트 루트 경로에 생성
$ vi Project.swift
$ open Project.swift
  • 프로젝트에 관한 기본 정보 입력
import ProjectDescription

// MARK: Constants
let projectName = "Jake"
let organizationName = "jake"
let bundleID = "com.jake.Jake"
let targetVersion = "14.0"

// MARK: Struct
let project = Project(
  name: projectName,
  organizationName: organizationName,
  packages: [],
  settings: nil,
  targets: [
    Target(name: projectName,
           platform: .iOS,
           product: .app, // unitTests, .appExtension, .framework, dynamicLibrary, staticFramework
           bundleId: bundleID,
           deploymentTarget: .iOS(targetVersion: targetVersion, devices: [.iphone]),
           infoPlist: .default,
           sources: ["\(projectName)/**"],
           resources: [],
           dependencies: [] // tuist generate할 경우 pod install이 자동으로 실행
          )
  ],
  schemes: [
    Scheme(name: "\(projectName)-Debug"),
    Scheme(name: "\(projectName)-Release")
  ],
  fileHeaderTemplate: nil,
  additionalFiles: [],
  resourceSynthesizers: []
)
  • 위에 정의한 구조대로 프로젝트 generate
$ tuist generate

결과)

  • before - Jake라는 모듈 안에 모든 파일이 존재
  • after - Proejct라는 모듈과 Frameworks라는 모듈로 분리 (다음 포스팅 글에서 의존성 관리도 확인)
before after
Tuist로 프로젝트 구조 변경

cf) 프로젝트가 존재하지 않고 처음 만들 경우, 아래 방법 사용

mkdir MyApp
cd MyApp
tuist init --platform ios

* 전체 코드: https://github.com/JK0369/EXTuist-Jake

* 참고

https://www.bam.tech/article/adopting-tuist-on-an-existing-project-tuist

 

Comments