nalexn / clean-architecture-swiftui

SwiftUI sample app using Clean Architecture. Examples of working with CoreData persistence, networking, dependency injection, unit testing, and more.
MIT License
5.56k stars 671 forks source link

DIContainer conforming EnvironmentKey - can't find its usage #93

Closed vanjang closed 3 weeks ago

vanjang commented 4 months ago

Just wonder why DIContainer conforms EnvironmentKey in the project as I am not able to find its usage with EnviromentValues across the project. The projects builds fine with commenting EnvironmentKey. Could anyone explain? I don't have enough knowledge on EnvironmentKey therefore I may miss something on how to use it.

Eirias commented 4 months ago

Check the RootViewModifier on the master branch, it uses: @Environment(\.injected) private var injected: DIContainer

which uses the extension EnvironmentValues { var injected: DIContainer { get { self[DIContainer.self] } set { self[DIContainer.self] = newValue } } }

from the DependencyInjector.

vanjang commented 4 months ago

Ah got it! I am on mvvm branch and it doesn't have the code you advised above. Thanks and problem solved!