swift-dependencies: an environment for Swift where Date, UUID and clocks become test controls
A dependency management library inspired by SwiftUI's "environment."
At a glance
- What is it?
- swift-dependencies from Point-Free borrows SwiftUI's environment idea to inject Date, UUID, clocks and your own clients into models, tests and previews. This covers the @Dependency property wrapper, the .dependencies test trait, the platform matrix in the Makefile and where the README stops.
- Who is it for?
- Adopt swift-dependencies when a Swift model reaches for Date(), UUID(), Task.sleep or a network client and the tests are slow or flaky because of it. Skip it if you want dependency injection with no property wrapper in your models and no test trait to learn.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 27 days ago.
- What is it written in?
- Mainly Swift, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 26, 2026, and from our analysis. They are not legal advice.
Star history
- pointfreeco/swift-dependencies2,202 ★ · +3
| Repository | 2026-10-08 | 2026-11-26 |
|---|---|---|
| pointfreeco/swift-dependencies | 2.2k | 2.2k |
3 Stars in the last 49 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Date(), UUID() and Task.sleep are the first dependencies it takes off your hands
The library starts from a narrow definition. A dependency is a type or function that interacts with a system you do not control. API clients that talk to servers are the classic case, but the README also counts UUID and Date initialisers, file access, user defaults, clocks and timers.
The cost of leaving them uncontrolled is spelled out in three points. Tests become hard to make fast and deterministic, because they depend on file systems, network connectivity, internet speed and server uptime. Some dependencies do not work in SwiftUI previews, such as location managers and speech recognizers, and some fail even in simulators, such as motion managers. Dependencies that wrap third-party libraries such as Firebase or web socket libraries are heavyweight and slow to compile.
The library also names three problems that appear after you have controlled a dependency. How do you propagate it through the app in a way that is more ergonomic than passing it everywhere and safer than a global? How do you override it for one part of the app, such as a test, a preview or an onboarding flow? How do you know you overrode every dependency a feature uses? A test that mocks some and leaves others talking to the real world is wrong.
Four @Dependency lines replace direct calls to the clock, the date, the queue and UUID
The quick start shows an @Observable model that declares what it needs through the @Dependency property wrapper, with key paths into DependencyValues:
@Observable
final class FeatureModel {
var items: [Item] = []
@ObservationIgnored
@Dependency(\.continuousClock) var clock // Controllable way to sleep a task
@ObservationIgnored
@Dependency(\.date.now) var now // Controllable way to ask for current date
@ObservationIgnored
@Dependency(\.mainQueue) var mainQueue // Controllable scheduling on main queue
@ObservationIgnored
@Dependency(\.uuid) var uuid // Controllable UUID creation
// ...
}Each property carries an @ObservationIgnored attribute, which matters because the model is @Observable and the wrapper should not be tracked as observable state. Combine schedulers count too, so code that uses them directly can adopt the library without a rewrite.
The full list of built-in dependencies lives in the DependencyValues documentation, not in the README. The library also lets you register your own.
The feature method stops calling Task.sleep, UUID() and Date() directly
Declaring the dependencies changes nothing until the logic uses them. The README's example method calls the injected values and marks the three calls it replaces:
func addButtonTapped() async throws {
try await clock.sleep(for: .seconds(1)) // 👈 Don't use 'Task.sleep'
items.append(
Item(
id: uuid(), // 👈 Don't use 'UUID()'
name: "",
createdAt: now // 👈 Don't use 'Date()'
)
)
}This is the real adoption cost. Every direct call to Date(), UUID() or Task.sleep in a feature has to be found and swapped for the injected property. A call you miss stays uncontrolled, and the test that was meant to be deterministic still depends on wall-clock time or a random identifier.
The library cannot detect that for you. Grep your feature code for those three initialisers before trusting a test.
The .dependencies test trait overrides the clock, date and UUID for one test only
Tests use Swift Testing, imported alongside Dependencies and DependenciesTestSupport. The .dependencies trait scopes overrides to a single test:
@Test(
// 1️⃣ Override any dependencies that your feature uses.
.dependencies {
$0.clock = .immediate
$0.date.now = Date(timeIntervalSinceReferenceDate: 1234567890)
$0.uuid = .incrementing
}
)Three overrides are at work. The date is pinned to a single value, so every call returns the same moment. The uuid dependency becomes an incrementing counter, so each call returns the next identifier and assertions can name exact values. The clock becomes an ImmediateClock, which squashes all time into a single instant, so a one-second sleep costs nothing.
Without those controls the README says this test would be very difficult to write, since nothing predicts what Date() and UUID() return and the test would wait for real time to pass. The overrides apply to that one test, so other tests keep their defaults.
Previews get the same override, which is how a view stops waiting for real time
Controllable dependencies are not limited to tests. The README argues the same mechanism helps in Xcode previews. If a feature sleeps on a clock before something happens in the view, overriding the clock to an immediate one means you do not have to wait to see how the view changes.
That addresses the second problem listed earlier, where some dependencies do not work in previews at all. A location manager or speech recognizer replaced by a controlled stand-in lets you iterate on the design of the feature.
The quick start text is cut off at the point where it explains the preview override, so the exact preview syntax is not in the README excerpt. The documentation pages hosted on Swift Package Index are where to look for the preview-specific code. Anything you read here about previews stops at the idea: override the clock with an immediate one.
The README also names onboarding flows as a place where overriding dependencies for one portion of the app is useful, which is a runtime use and not only a test or preview use.
The Makefile tests five Apple platforms and Linux, and builds with library evolution
The Makefile shows how far the package is exercised. The build-all-platforms target loops over iOS Simulator, macOS, Mac Catalyst, tvOS Simulator and watchOS Simulator, running xcodebuild against the Dependencies scheme in Dependencies.xcworkspace. The test-swift target runs swift test in debug and release with a define:
swift test -Xswiftc -D -Xswiftc EXCLUDE_EXPORTSLinux is covered by test-linux, which runs make test-swift inside a swift:6.3-noble Docker image. A static standard library build, swift build with --static-swift-stdlib, is tested in both debug and release. A separate Integration scheme runs on the iOS simulator.
The library-evolution target builds the Dependencies and DependenciesMacros targets in release with module interfaces emitted. For DependenciesMacros it also passes -DRESILIENT_LIBRARIES, which the Makefile comment says is required to build swift-syntax. Anyone shipping a binary framework with library evolution enabled should know the macros target needs that flag.
Three manifests sit in the root: Package.swift, [email protected] and [email protected]. SwiftPM picks the one matching your toolchain.
The README ends before the Installation, Extensions and Alternatives sections
The table of contents lists Learn More, Overview, Quick start, Examples, Documentation, Installation, Community, Extensions, Alternatives and License. The text available stops inside the Quick start, so what the Examples, Extensions and Alternatives sections contain cannot be reported here. In particular, the version requirement for adding the package is not given.
What can be checked is the release history: 1.17.1 on 2026-08-28, 1.17.0 on 2026-08-24 and 1.16.0 on 2026-08-18. Three releases landed inside eleven days, and the last push on 2026-10-19 is after the latest tag. The repository is not archived and the licence is MIT.
The library came out of episodes of Point-Free, a video series on functional programming and Swift hosted by Brandon Williams and Stephen Celis. The design was worked out in public over those episodes, so the videos are the longest explanation of why the API looks the way it does.
The README promises that the library addresses all of the problems above and much more. That claim is the authors' own, and the only check available here is running your own feature against it.
Editorial conclusion
Adopt swift-dependencies when a Swift model reaches for Date(), UUID(), Task.sleep or a network client and the tests are slow or flaky because of it. Skip it if you want dependency injection with no property wrapper in your models and no test trait to learn. Before committing, read the Alternatives section of the README and check the Swift version manifests against your toolchain.
Frequently asked questions
What is a dependency example in swift-dependencies?
A dependency is a type or function that talks to a system you do not control. Examples named are API clients, UUID and Date initialisers, file access, user defaults, clocks and timers.
How can I use dependency injection in Swift with swift-dependencies?
Declare what a model needs with the @Dependency property wrapper, such as @Dependency(\.uuid), then call the injected value in place of UUID(). In tests, the .dependencies trait overrides them for a single test.
What are all the dependencies swift-dependencies controls?
The README sends readers to the DependencyValues documentation for the full list. It names Date, UUID, Task.sleep and Combine schedulers as ones you can use immediately, and lets you register your own.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/pointfreeco-swift-dependencies)Star history chart for your README
[](https://hysenlabs.com/projects/pointfreeco-swift-dependencies)Was this useful?