Usage Commands Cloud Contributors

Third-party dependencies

Third-party dependencies are great to save some development time by reusing code that has been developed by other developers. Originally, CocoaPods was the leading dependency manager developed and maintained by the community. It’s still extensively used because most dependencies support it by default. Eventually, Carthage came out with a different approach for distributing and consuming dependencies from projects: dependencies are decentralized and integrated into projects as pre-compiled dynamic frameworks.

With the introduction of Swift, Apple presented a new dependency manager, Swift Package Manager. Dependencies are decentralized (like Carthage) and integrated as source code (like CocoaPods). One of the benefits of the Swift Package Manager over the other dependency managers is that it has better integration with Xcode and existing projects. For that reason, some teams have started migrating their dependencies to packages, and in some cases, using them to describe their projects as packages.

Tuist and the Swift Package Manager

Like Tuist, the Swift Package Manager can be used for describing local projects. However, the Swift Package Manager's interface is designed for packages and not for projects. For example, there's no interface for describing schemes or choose the directory structure. Moreover, unlike Tuist, the Swift Package Manager is not designed to support teams in their scalability efforts. That means developers don't get features like caching or insights that are crucial for the healthy growth of a project.

1. Swift Packages

Swift Packages are nodes in your project’s dependency tree that represent static libraries. You can add them to your projects by using the interface designed for that:

// Project.swift
import ProjectDescription
let project = Project(name: "App",
packages: [
.package(url: "https://github.com/ReactiveX/RxSwift", .upToNextMajor(from: "5.0.0")),
],
targets: [
Target(name: "App",
platform: .iOS,
product: .app,
bundleId: "io.tuist.App",
sources: ["Sources/**"],
dependencies: [
.package(product: "RxSwift"),
.package(product: "RxBlocking")
]),
])
Copy the content

2. Carthage

Carthage frameworks are nodes in your project’s dependency tree. Thus, Tuist can validate the dependency and make sure they are properly integrated into the generated project. We recommend following the project structure below:

Setup.swift
Setup file with the steps to configure the environment before working on the project.
Cartfile
Lists all the Carthage dependencies.
Carthage
The directory where Carthage pulls the dependencies.
Tuist
A global Tuist's directory.
Projects
A directory that contains all the projects.
App
A contains the app project.
Project.swift
The app's Project.swift. It can import helpers.

Then we can add a .carthage step to the Setup.swift file to pull the Carthage dependencies when running tuist up:

// Setup.swift
import ProjectDescription
let setup = Setup([
.carthage(platforms: [.iOS])
])
Copy the content

From any target you can specify a dependency with a Carthage framework as shown in the example below:

// Project.swift
import ProjectDescription
let project = Project(name: "App",
targets: [
Target(name: "App",
platform: .iOS,
product: .app,
bundleId: "io.tuist.App",
sources: ["Sources/**"],
dependencies: [
.framework(path: .relativeToRoot("Carthage/Build/iOS/Framework.framework"))
])
])
Copy the content

By using this website, you agree to our cookie policy.