一个自以为是的 SwiftUI 项目模板
适用于Tuist的SwiftUI模板
Tuist 是管理 Swift 项目的好工具。
但我仍然需要编写很多代码来配置我的项目。
所以我决定分享我的配置。 是我对 的 opionated 配置。SwiftUItemplate
Tuist
安装
- 通过以下方式创建您的第一个项目
tuist init --platform ios
- 打开 ,将其更改为
Tuist/Config.swift
import ProjectDescription
let config = Config(
plugins: [
.git(url: "https://github.com/haifengkao/SwiftUITemplate", branch: "main")
]
)
- 在终端中运行下载
tuist fetch
SwiftUITemplate
如果上述过程不起作用,请查看Tuist文档以获取更多信息。
用法
SwiftUITemplate
遵循微特征架构。
应用程序由多个微功能组成。每个包含microfeature
- 用于演示功能的示例目标
- 用于测试功能的单元测试目标
- 实现该功能的框架代码
可能是或快速包(不支持Cocoapods和Carthage,欢迎PR)。module
microfeature
要添加 ,请创建 。
然后将 添加到 ,例如microfeature
Tuist/ProjectDescriptionHelpers/Modules.swift
microfeature
modules
import ProjectDescription
import SwiftUITemplate
private extension Module {
static var MyApp: Module {
.uFeature(name: "MyApp", targets: [
.exampleApp: .resourcesOnly,
.unitTests: .default,
.framework: .default,
])
}
}
public let modules: [Module] = [
Module.MyApp,
Module.Quick,
Module.Nimble,
]
By default, uses Nimble and Quick as the unit test framework. It’s mandatory to include and for the unit test placeholder codes to compileSwiftUITemplate
Nimble
Quick
You can specify project name and the targets in .Project.swift
import ProjectDescription
import ProjectDescriptionHelpers
import SwiftUITemplate
let project: Project = Project(name: "MyApp",
organizationName: "example.SwiftUITemplate",
targets: modules.allProjectTargets)
modules.allProjectTargets
tells to include all targets(exampleApp, unit test, frameworks) into the generated project.tuist
To include swift packages, we can create a swift package with .
The following example adds into ‘s framework traget..package
Alamofire
MyApp
import ProjectDescription
import SwiftUITemplate
private extension Module {
static var MyApp: Module {
.uFeature(name: "MyApp", targets: [
.exampleApp: .resourcesOnly,
.unitTests: .default,
.framework: .hasDependencies([
.Alamofire
]),
])
}
static var Alamofire: Module {
.package(name: "Alamofire", url: "https://github.com/Alamofire/Alamofire", requirement: .upToNextMajor(from: "5.5.0"))
}
}
public let modules: [Module] = [
Module.MyApp,
Module.Quick,
Module.Nimble,
]
We don’t have to add into because will automatically find in ‘s dependencies.Module.Alamofire
modules
SwiftUITemplate
Module.Alamofire
Module.MyApp
Tuist
requires us to specify swift packages in .
So we have to create with the following contentDependencies.swift
Tuist/Dependencies.swift
import ProjectDescription
import ProjectDescriptionHelpers
import SwiftUITemplate
let dependencies = Dependencies(
swiftPackageManager: .init(
modules.allSwiftPacakges,
targetSettings: modules.allTargetSettings
),
platforms: [.iOS]
)
SwiftUITemplate
will find out all swift packages defined in and its dependencies.modules
To generate the .xcworkspace
- run to download swift packages
tuist fetch
- run to generate xcworkspace
tuist generate
If the above procedure doesn’t work, please check Tuist tutorial for more info.
TargetConfig
TargetConfig
has four modes
default
indicates the target has no resources to include and no dependencies to other modulesresourcesOnly
indicates the target has resources but no dependencieshasDependencies([Modules])
let you specify the target’s dependencieshasResourcesAndDependencies([Modules])
indicates the target has resources and dependencies
File structure
├── Tuist
│ └── (Tuist setting files)
└── Features
├── MyApp
│ ├── Example (example target codes)
│ ├── Tests (unit test target codes)
│ └── Sources (framework codes)
└── MyFeature1
├── Example
├── Tests
└── Sources
All features are located in folder. will find corresponding codes and resources in the predefined subfolders.Features
SwiftUITemplate
This plugin provides a command to create a microfeature’s placeholder files (unimplemented).
tuist swiftui create MyFeature1
Contribute
To start working on the project, you can follow the steps below:
- Clone the project.
- cd
fixtures/Example1
tuist fetch
to install the plugintuist edit
to add new modulestuist generate
to generate xcworkspace