How pointfreeco/swift-dependencies works
Project type and purpose
• This is an open-source Swift dependency-management library (a SwiftPM package) that provides:
• A core “Dependencies” runtime API for registering, retrieving, and overriding dependencies at runtime.
• A set of Swift macros (via the DependenciesMacros and DependenciesMacrosPlugin targets) to generate boilerplate code.
• Test support utilities and a demo “Integration” SwiftUI app to validate usage.
File structure
• Top-level Swift package manifest and workspace files (Package.swift, .xcworkspace, Xcode schemes).
• Sources/Dependencies: The core library API.
• Sources/DependenciesMacros: Macro definitions (entry points, exports).
• Sources/DependenciesMacrosPlugin: The SwiftPM plugin that the compiler invokes to expand macros.
• Sources/DependenciesTestSupport & DependenciesTestObserver: Test-time overrides and observers.
• Integration/: An Xcode app project demonstrating how to consume the library in a SwiftUI app.
• Tests/: Unit tests for each module (core, macros plugin, test support).
README for additional insights
• Purpose: control “environment”-style dependencies in Swift, override for tests and previews, provide single-entry-point lifecycle.
• Key technologies: Swift User-Defined Macros, SwiftPM plugins, Swift concurrency, SwiftUI previews, XCTest.
Elements
• Rectangles for modules/targets (Core, Macros, Plugin, TestSupport, Demo App)
• Core library in blue
• Macros & Plugin in green
• Test support in orange
• Demo app in purple
• Build system & compiler in gray
• From Build System → Plugin (code-gen invocation)
• Plugin → Core Library (macro-expansion output)
• Demo App → Core Library (runtime link)
• Tests → Core Library + TestSupport (link & override)
• Demo App / Tests → SwiftUI / XCTest frameworks