建立生成項目
在任何目錄或現有項目目錄中開始使用 Tuist 的最簡單方法:
mise x tuist@latest -- tuist initmise x tuist@latest -- tuist init
bash
mise x tuist@latest -- tuist init
tuist inittuist init
bash
tuist init
此指令會引導你完成建立生成項目或整合現有 Xcode 項目或工作區的步驟。它幫助你將設定連接到遠端伺服器,讓你可以使用選擇性測試、預覽和註冊表等功能。
新增依賴項#
項目通常依賴第三方庫來提供額外功能。為此,請執行以下指令以獲得最佳的項目編輯體驗:
bash
tuist edit
將會開啟一個包含你項目檔案的 Xcode 項目。編輯 Package.swift 並新增
swift
// swift-tools-version: 5.9
import PackageDescription
#if TUIST
import ProjectDescription
let packageSettings = PackageSettings(
// Customize the product types for specific package product
// Default is .staticFramework
// productTypes: ["Alamofire": .framework,]
productTypes: [:]
)
#endif
let package = Package(
name: "MyApp",
dependencies: [
// Add your own dependencies here:
// .package(url: "https://github.com/Alamofire/Alamofire", from: "5.0.0"),
// You can read more about dependencies here: https://docs.tuist.io/documentation/tuist/dependencies
.package(url: "https://github.com/onevcat/Kingfisher", .upToNextMajor(from: "7.12.0")) // [!code ++]
]
)
然後編輯項目中的應用程式目標,將 Kingfisher 宣告為依賴項:
swift
import ProjectDescription
let project = Project(
name: "MyApp",
targets: [
.target(
name: "MyApp",
destinations: .iOS,
product: .app,
bundleId: "dev.tuist.MyApp",
infoPlist: .extendingDefault(
with: [
"UILaunchStoryboardName": "LaunchScreen.storyboard",
]
),
buildableFolders: [
"MyApp/Sources",
"MyApp/Resources",
],
dependencies: [
.external(name: "Kingfisher") // [!code ++]
]
),
.target(
name: "MyAppTests",
destinations: .iOS,
product: .unitTests,
bundleId: "dev.tuist.MyAppTests",
infoPlist: .default,
sources: ["MyApp/Tests/**"],
resources: [],
dependencies: [.target(name: "MyApp")]
),
]
)
然後執行 tuist install 以使用 Swift Package Manager 解析並拉取依賴項。
使用 SPM 作為依賴項解析器
Tuist 建議的依賴項處理方法僅使用 Swift Package Manager (SPM) 來解析依賴項。然後 Tuist 會將它們轉換為 Xcode 項目和目標,以實現最大的可配置性和控制力。
視覺化項目#
你可以通過執行以下指令來視覺化項目結構:
bash
tuist graph
該指令將在項目目錄中輸出並開啟一個 graph.png 檔案:

使用依賴項#
執行 tuist generate 以在 Xcode 中開啟項目,並對 ContentView.swift 檔案進行以下更改:
swift
import SwiftUI
import Kingfisher // [!code ++]
public struct ContentView: View {
public init() {}
public var body: some View {
Text("Hello, World!") // [!code --]
.padding() // [!code --]
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
從 Xcode 運行應用程式,你應該會看到從 URL 載入的圖像。