Factory
Compile-time safe dependency injection for Swift and SwiftUI apps
All Skills in This Repository (2)
Pure Emerald Level IndicatorsFrequently Asked Questions
FAQPage SchemaHow to install Factory?โผ
Run `npx skills add hmlongco/Factory --all -g -y` in your terminal to install all skills in this suite globally.
What is Factory for Swift?โผ
Factory is a lightweight, compile-time safe dependency injection library for Swift and SwiftUI. It lets you register and resolve services through containers with a single line of code.
How do I mock dependencies in Swift tests with Factory?โผ
Register a mock closure on the container's factory, such as `Container.shared.myService.register { MockService() }`. The FactoryTesting trait gives each Swift Testing test an isolated container automatically.
Does Factory work with SwiftUI and @Observable?โผ
Yes. Factory provides `@InjectedObject` for ObservableObject view models and `@InjectedObservable` for iOS 17+ @Observable types, plus preview modifiers for swapping in mocks.
How is Factory different from Swinject or Needle?โผ
Factory needs no code generation, build phases, or upfront type registration. Each dependency is a computed property on a container, so missing registrations fail at compile time instead of runtime.
Related Repositories in Software Engineering
View All in Software Engineeringโopenclaw
Run a personal AI assistant across your devices and chat apps
superpowers
Gives coding agents a disciplined workflow from idea to merged code
react
AI agent skills for building, testing, and porting React core