建立生成的專案
在空白目錄或現有專案的目錄中執行 tuist init:
mise x tuist@latest -- tuist init
mise x tuist@latest -- tuist init
bash
mise x tuist@latest -- tuist init
tuist init
tuist init
bash
tuist init
此指令會引導你完成建立生成的專案或整合現有 Xcode 專案或工作區的步驟。它能協助你將設定連線至遠端伺服器,讓你使用如選擇性測試、預覽與套件註冊表等功能。
新增相依性#
專案常需仰賴第三方函式庫來提供額外功能。為此,請執行以下指令以獲得最佳的專案編輯體驗:
bash
tuist edit
系統將開啟包含你專案檔案的 Xcode 專案。編輯 Tuist/Package.swift 並加入 Kingfisher:
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://tuist.dev/en/docs/guides/features/projects/dependencies
.package(url: "https://github.com/onevcat/Kingfisher", .upToNextMajor(from: "7.12.0"))
]
)
接著編輯專案中的應用程式目標,將 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")
]
),
.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 解析並拉取相依性。
使用 SwiftPM 作為相依性解析器
Tuist 建議的相依性處理方式僅使用 Swift Package Manager (SPM) 來解析相依性。隨後 Tuist 會將其轉換為 Xcode 專案與目標,以提供最大的可設定性與控制力。
視覺化專案結構#
你可以執行以下指令來視覺化專案結構:
bash
tuist graph
此指令會在專案目錄中輸出並開啟 graph.png 檔案:

使用相依性#
執行 tuist generate 以在 Xcode 中開啟專案,並對 ContentView.swift 檔案進行以下變更:
swift
import SwiftUI
import Kingfisher
public struct ContentView: View {
public init() {}
public var body: some View {
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
從 Xcode 執行應用程式,你應該會看到從 URL 載入的圖片。