Needle is a dependency injection (DI) system for Swift. Unlike other DI frameworks, such as Cleanse, Swinject, Needle encourages hierarchical DI structure and utilizes code generation to ensure compile-time safety. This allows us to develop our apps and make changes with confidence. If it compiles, it works. In this aspect, Needle is more similar to Android Dagger.
Using and integrating with Needle has two steps. Each of the following steps has detailed instructions and explanations in the linked documents.
- Integrate Needle's code generator with your Swift project.
- Write application DI code following NeedleFoundation's API.
Needle has two parts, the NeedleFoundation
framework and the executable code generator. Both parts need to be integrated with your Swift project in order to use Needle as your DI system.
Install NeedleFoundation
framework via Carthage
Please follow the standard Carthage installation process to integrate the NeedleFoundation
framework with your Swift project.
github "https://github.com/uber/needle.git" ~> VERSION_OF_NEEDLE
Install NeedleFoundation
framework via CocoaPods
Coming soon!
Install code generator via Carthage
If Carthage is used to integrate the NeedleFoundation
framework, then a copy of the code generator executable of the corresponding version is already downloaded in the Carthage folder. It can be found at Carthage/Checkouts/needle/Generator/bin/needle
.
Install code generator via Homebrew
Coming soon!
The linked document uses a somewhat real example to explain what the dependency injection pattern is, and its benefits.