Tuist is a great tool to manage Swift projects.
But I still have to write a lot of codes to config my project.
So I decide to share my configuration. SwiftUItemplate is my opionionated configuration for Tuist.
- create your first project by
tuist init --platform ios - open
Tuist/Config.swift, change it to
import ProjectDescription
let config = Config(
plugins: [
.git(url: "https://github.com/haifengkao/SwiftUITemplate", tag: "0.5.0")
]
)- run
tuist fetchin terminal to downloadSwiftUITemplate
If the above procedure doesn't work, please check Tuist documentation for more info.
SwiftUITemplate follows microfeature architecture.
An app is composed by mutiple microfeatures. Each microfeature contains
- example target to deomstrate the feature
- unit test target to test the feature
- framework codes which implements the feature
A module might be microfeature or a swift package (Cocoapods and Carthage are not supported, PR welcome).
To add a microfeature, create Tuist/ProjectDescriptionHelpers/Modules.swift.
Then add the microfeature to modules, e.g.
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,
]You can specify 4 different kinds of targets:
.frameworkthe framework codes which other modules can depend on.unitTeststhe unit test target to test the framework.exampleAppthe example target.uiTeststhe ui test target which will run over example app
TargetConfig has four modes
.defaultindicates the target has no resources to include and no dependencies to other modules.resourcesOnlyindicates the target has resources but no dependencies.hasDependencies([Modules])let you specify the target's dependencies.hasResourcesAndDependencies([Modules])indicates the target has resources and dependencies
By default, SwiftUITemplate uses Nimble and Quick as the unit test framework. It's mandatory to include Nimble and Quick for the unit test placeholder codes to compile
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 tuist to include all targets(exampleApp, unit test, frameworks) into the generated project.
To include swift packages, we can create a swift package with .package.
The following example adds Alamofire into MyApp's framework traget.
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 Module.Alamofire into modules because SwiftUITemplate will automatically find Module.Alamofire in Module.MyApp's dependencies.
Tuist requires us to specify swift packages in Dependencies.swift.
So we have to create Tuist/Dependencies.swift with the following content
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 modules and its dependencies.
To generate the .xcworkspace
- run
tuist fetchto download swift packages - run
tuist generateto generate xcworkspace
If the above procedure doesn't work, please check Tuist tutorial for more info.
├── 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 Features folder. SwiftUITemplate will find corresponding codes and resources in the predefined subfolders.
This plugin provides templates to create a microfeature placeholder files
tuist scaffold ufeature --name MyFeature1 --company TuistDemoIt will create MyFeature1 in Features folder.
A LLM generated wiki
I am too lazy to write a complete doc
To start working on the project, you can follow the steps below:
- Clone the project.
- cd
fixtures/Example1 tuist fetchto install the plugintuist editto modify the plugin filestuist generateto generate the example xcworkspace. Use this command to check if the plugin works correctly