티스토리 뷰

iOS

[iOS] Tuist 사용법 - Dependencies (2)

Kim_Baechu 2021. 9. 17. 11:58

Defendencies.swift 만들기

Tuist/ProjectDescriptionHelpers 폴더에 새로운 파일 추가

만약 프로젝트 디렉토리에 Tuist/ProjectDescriptionHelpers가 없으면 생성해줍니다.

Defendencies.swift파일을 만들어줍니다.

그리고 다음과 같이 작성합니다.

민소네님의 글을 참고했습니다

http://minsone.github.io/mac/ios/ios-project-generate-with-tuist-3

 

[iOS][Tuist] 프로젝트 생성/관리 도구 Tuist(3) - Extension

 

import ProjectDescription

public extension TargetDependency {
    static let firebaseAnalytics: TargetDependency = .package(product: "FirebaseAnalytics")
    static let firebaseMessaging: TargetDependency = .package(product: "FirebaseMessaging")
    static let firebaseCrashlytics: TargetDependency = .package(product: "FirebaseCrashlytics")
    
    static let rxSwift: TargetDependency = .package(product: "RxSwift")
    static let rxCocoa: TargetDependency = .package(product: "RxCocoa")
    static let rxFlow: TargetDependency = .package(product: "RxFlow")
    static let rxDataSources: TargetDependency = .package(product: "RxDataSources")
    
    static let moyaRxSwift: TargetDependency = .package(product: "RxMoya")
    static let snapKit: TargetDependency = .package(product: "SnapKit")
    static let swiftyJSON: TargetDependency = .package(product: "SwiftyJSON")
    static let swiftyBeaver: TargetDependency = .package(product: "SwiftyBeaver")
    static let lottieios: TargetDependency = .package(product: "Lottie")
    static let kingfisher: TargetDependency = .package(product: "Kingfisher")
}

public extension Package {
    static let firebase: Package = .package(url: "https://github.com/firebase/firebase-ios-sdk.git", from: "8.0.0")
    
    static let rxSwift: Package = .package(url: "https://github.com/ReactiveX/RxSwift.git", .exact("5.1.1"))
    static let rxFlow: Package = .package(url: "https://github.com/RxSwiftCommunity/RxFlow.git", from: "2.11.0")
    static let rxDataSources: Package = .package(url: "https://github.com/RxSwiftCommunity/RxDataSources.git", from: "4.0.0")
    
    static let moyaRxSwift: Package = .package(url: "https://github.com/Moya/Moya.git", from: "14.0.0")
    static let snapKit: Package = .package(url: "https://github.com/SnapKit/SnapKit.git", .upToNextMajor(from: "5.0.1"))
    static let swiftyJSON: Package = .package(url: "https://github.com/SwiftyJSON/SwiftyJSON.git", .upToNextMajor(from: "4.0.0"))
    static let swiftyBeaver: Package = .package(url: "https://github.com/SwiftyBeaver/SwiftyBeaver.git", .upToNextMajor(from: "1.9.0"))
    static let lottieios: Package = .package(url: "https://github.com/airbnb/lottie-ios.git", from: "3.2.1")
    static let kingfisher: Package = .package(url: "https://github.com/onevcat/Kingfisher.git", .upToNextMajor(from: "5.15.6"))
}

// MARK: SourceFile
public extension SourceFilesList {
    static let sources: SourceFilesList = "Sources/**"
    static let tests: SourceFilesList = "Tests/**"
}

// MARK: Resource
public enum ResourceType: String {
    case xibs = "Sources/**/*.xib"
    case storyboards = "Resources/**/*.storyboard"
    case assets = "Resources/**"
}

// MARK: Extension
public extension Array where Element == FileElement {
    static func resources(with resources: [ResourceType]) -> [FileElement] {
        resources.map { FileElement(stringLiteral: $0.rawValue) }
    }
}

 

Package에서 Swift Package를 등록하시면 됩니다.

다음 예시는 Swift package manager가 다음 버전을 선택합니다.

1.2.3, 1.2.4 또는 1.3.0설치, 2.0.0은 설치하지 않음

.package(url: "https://example.com/example-package.git", from: "1.2.3"),

 

다음 예시는 Swift package manager가 다음 버전을 선택합니다.

1.2.3, 1.2.4, 1.2.5설치, 1.2.6은 설치하지 않음

.package(url: "https://example.com/example-package.git", "1.2.3"..<"1.2.6"),

 

Requirement enum 을 사용해서 나타낼 수도 있습니다.

public enum Requirement : Codable, Equatable {

        case upToNextMajor(from: ProjectDescription.Version)

        case upToNextMinor(from: ProjectDescription.Version)

        case range(from: ProjectDescription.Version, to: ProjectDescription.Version)

        case exact(ProjectDescription.Version)

        case branch(String)

        case revision(String)
...
}

 

Project파일에서 사용하기

예시)

let packages: [Package] = [
    .firebase,
    .rxSwift,
    .rxFlow,
    .rxDataSources,
    .moyaRxSwift,
    .snapKit,
    .kingfisher,
    .lottieios,
    .swiftyBeaver,
    .swiftyJSON,
]

let dependencies: [TargetDependency] = [
    .firebaseAnalytics,
    .firebaseMessaging,
    .firebaseCrashlytics,
    .rxCocoa,
    .rxFlow,
    .rxDataSources,
    .kingfisher,
    .snapKit,
    .lottieios,
    .swiftyJSON,
    .swiftyBeaver,
    .moyaRxSwift,
]

 

코코아팟(Cocoapods) 사용하기

Target(
    name: "MyApp"
    platform: .iOS,
		...
    dependencies: [
        .cocoapods(path: "."),
    ]
)
댓글
공지사항