iOS/SwiftUI + Combine

[SwiftUI][tuist] - tuist 설치 및 세팅

곰돌이도한다. 2022. 4. 23. 15:38

SwiftUI 기준이다.

 

참고 : https://docs.tuist.io/tutorial/get-started/

 

Get started | Tuist Documentation

Learn how to install Tuist in your environment and generate your first project.

docs.tuist.io

 

tuist 설치

curl -Ls https://install.tuist.io | bash

 

 

폴더생성

mkdir MyApp
cd MyApp

 

 

프로젝트 생성

tuist init --platform ios --template swiftui

 

 

Project.swift 수정

tuist edit

 

tuist edit을 실행하여 Project.swift를 수정하자.

설치할 library 및 프로젝트 세팅, plist 설정 등 전반적으로 설정이 가능하다.

 

Project.swift : di(pod, spm, carthage) 연결, plist, project setting

Dependencies.swift : 사용할 di 상세정보 정리, Project.swift에서 .external로 연결.

 

 

 

Dependencies.swift

 

import ProjectDescription

 

let dependencies = Dependencies(

//    carthage: [

//        .github(path: "Alamofire/Alamofire", requirement: .exact("5.0.4")),

//    ],

    swiftPackageManager: [

        .remote(url: "https://github.com/Alamofire/Alamofire", requirement: .upToNextMajor(from: "5.6.1")),

    ],

    platforms: [.iOS]

)

 

 

 

Project.swift

 

import ProjectDescription

 

let version: InfoPlist.Value = "1.0.0"

let projectName: String = "projectName" /// 프로젝트 이름

let organizationName: String = "organizationName." /// organization 이름

let bundleName: String = "com.company" /// 번들 앞 prefix -> 이렇게 안해줘도 됨

 

/// info

let infoPlist: [String: InfoPlist.Value] = [

    "CFBundleShortVersionString": version,

    "CFBundleVersion": "1",

    "UIMainStoryboardFile": "",

    "UILaunchStoryboardName": "LaunchScreen",

    "CFBundleURLTypes": [

        "1", "2", "3"

    ],

    "FacebookAppID":"1111111",

    "FacebookDisplayName":"111",

    "FirebaseDynamicLinksCustomDomains": [

        "https://naver.com"

    ],

    "GADApplicationIdentifier":"1111",

    "KAKAO_APP_KEY":"1111",

    "LSApplicationQueriesSchemes": [

        "111",

        "222",

        "333"

    ],

    "LSSupportsOpeningDocumentsInPlace":true,

    "NSAppleMusicUsageDescription":"",

    "NSCameraUsageDescription":"",

    "NSContactsUsageDescription":"",

    "NSLocationWhenInUseUsageDescription":"",

    "NSMicrophoneUsageDescription":"",

    "NSPhotoLibraryAddUsageDescription":"",

    "NSPhotoLibraryUsageDescription":"",

    "NSUserTrackingUsageDescription":"",

    "UIFileSharingEnabled":true

]

 

/// 앱의 타겟 설정

let targets = [

    Target(

        name: projectName, /// 타겟 이름

        platform: .iOS, /// 플랫폼

        product: .app, /// 앱인지 프레임워크인지 라이브러리인지 등

        bundleId: "\(bundleName).\(projectName)", /// 번들 아이디

        deploymentTarget: .iOS(targetVersion: "14.0", devices: [.iphone]),

        //infoPlist: "\(projectName)/Supporting/Info.plist", /// 파일로 관리할경우 이걸로

        infoPlist: .extendingDefault(with: infoPlist),

        sources: [

            "\(projectName)/Sources/**"

        ],

        resources: [

            "\(projectName)/Resources/**"

        ],

        entitlements: "\(projectName)/Supporting/111.entitlements",

//        actions: targetActions, /// 빌드 스크립트 실행

        dependencies: [

            //.cocoapods(path: ".") /// 코코아 팟으로 의존성 관리, tuist generate하면 pod install 자동으로 됨

            .external(name: "Alamofire")

        ]

    ),

    Target( /// unit test

        name: "\(projectName)Tests",

        platform: .iOS,

        product: .unitTests,

        bundleId: "\(bundleName).\(projectName)Tests",

        infoPlist: "\(projectName)Tests/Info.plist",

        sources: "\(projectName)Tests/**",

        dependencies: [

            .target(name: projectName) /// 테스트의 의존성은 실제 프로젝트에 있음

        ]

    ),

    Target( /// ui test

        name: "\(projectName)UITests",

        platform: .iOS,

        product: .uiTests,

        bundleId: "\(bundleName).\(projectName)UITests",

        infoPlist: "\(projectName)UITests/Info.plist",

        sources: "\(projectName)UITests/**",

        dependencies: [

            .target(name: projectName)

        ]

    )

]

 

/// 실제 프로젝트

let project = Project(

    name: projectName,

    organizationName: organizationName,

//    settings: settings,

    targets: targets

//    schemes: schemes

)

 

 

이 상태에서 tuist generate 명령어를 치면 에러가 간다.

path 지정한 곳에 폴너가 파일이 없는 경우가 대부분이라 경로에 맞게 폴더나 파일을 추가하거나 이동시켜준다.

Sources 폴더에 실행파일(.swift)이 들어가며 해당 폴더안에 있으면 어떤 폴더나 파일을 만들던 전부 적용이 된다.

 

 

프로젝트 생성 및 수정사항 적용 후 빌드

tuist generate

 

 

 

.ignore 추가

tuist를 사용하는 이유가 협업 시 파일 추가등으로 .xcodeproj, .xcworkspace가 conflict가 나는 문제를 해결하기 위해서다.

.xcodeproj, .xcworkspace가 git에 올라가면 안되고 tuist generate로 생성이 되어야 한다.

.ignore에 아래를 추가해준다.

*.xcodeproj
*.xcworkspace

 

 

참고) .ignore 만드는법

https://www.toptal.com/developers/gitignore

 

gitignore.io

Create useful .gitignore files for your project

www.toptal.com

여기서 xcode, pod, swift를 추가해서 생성버튼을 누르면 관련 .ignore가 생성된다.

'iOS > SwiftUI + Combine' 카테고리의 다른 글

[SwiftUI][tuist, mise] - 설치, 2024기준  (0) 2024.11.19
[SwiftUI][tuist] - 간단한 사용  (0) 2022.04.23