FileSystem is a Swift Package that provides a simple cross-platform API to interact with the file system.
Why build a Swift Package for interacting with the file system if there's already FileManager
? Here are the motivations:
- Providing human-friendly errors that are ok to present to the user.
- Integrating with swift-log to give consumers the ability to log file system operations.
- Embracing Swift's structured concurrency with async/await.
- Providing an API where paths are always absolute, makes it easier to reason about the file system operations.
Note
FileSystem powers Tuist, a toolchain to build better apps faster.
You can edit your project's Package.swift
and add FileSystem
as a dependency:
import PackageDescription
let package = Package(
name: "MyProject",
dependencies: [
.package(url: "https://github.com/tuist/FileSystem.git", .upToNextMajor(from: "0.1.0"))
],
targets: [
.target(name: "MyProject",
dependencies: ["FileSystem", .product(name: "FileSystem", package: "FileSystem")]),
]
)
First, you'll have to add the FileSystem
package to your project's Package.swift
file:
import PackageDescription
let package = Package(
name: "MyProject",
dependencies: [
.package(url: "https://github.com/tuist/FileSystem.git", .upToNextMajor(from: "0.1.0"))
]
)
And then declare it as a dependency of one of your project's targets:
// Project.swift
import ProjectDescription
let project = Project(
name: "App",
organizationName: "tuist.io",
targets: [
.target(
name: "App",
destinations: [.iPhone],
product: .app,
bundleId: "io.tuist.app",
deploymentTargets: .iOS("13.0"),
infoPlist: .default,
sources: ["Targets/App/Sources/**"],
dependencies: [
.external(name: "FileSystem"),
]
),
]
)
- Clone the repository:
git clone https://github.com/tuist/FileSystem.git
- Generate the project:
tuist generate
- Clone the repository:
git clone https://github.com/tuist/FileSystem.git
- Open the
Package.swift
with Xcode