Injected is a Swift Package Manager (SPM) package that provides a property wrapper for dependency injection in Swift projects. It simplifies the process of injecting dependencies into your code, making it more modular and testable.
@InjectedProperty Wrapper: Easily inject dependencies using the@Injectedproperty wrapper.InjectionKeyProtocol: Implement theInjectionKeyprotocol for custom injection keys.- Shared State Management: Manage shared state with the
InjectedValuesstructure.
To integrate this library into your Xcode project using Swift Package Manager, follow these steps:
- Open your Xcode project.
- Navigate to the menu
File > Swift Packages > Add Package Dependency.... - Enter the following URL of this repository:
git@github.com:VictorKreniski/Injected.git. - Click Next and select the version or branch you want to use.
- Click Next and then Finish.
The library will be automatically resolved and linked with your Xcode project.
- Import the
Injectedmodule:
import Injected- Define an injection key using the
InjectionKeyprotocol:
private struct TestInjectedValues: InjectionKey {
static var currentValue: String = ""
}- Use the
@Injectedproperty wrapper to inject dependencies:
@Injected(\.testValue) var testValue- Set and get values using the injected property:
testValue = "Updated String"
print(testValue) // Output: "Updated String"Injected is available under the MIT license. See the LICENSE file for more info.
For any questions or suggestions, feel free to open an issue.