Skip to content

Dependencies Don't Propagate to Nested Views #133

Answered by mbrandonw
dafurman asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @dafurman, the @Dependency property wrapper is not meant to be used in views if you need to be able to scope/propagate dependency changes. It is not even possible to have dependencies propagate to views without SwiftUI opening up more of its internals. By doing this:

withDependencies {
  $0.text = "Injected  - withDependencies"
} operation: {
  OuterView()
}

…you are only executing the initializer of OuterView with the dependencies altered, not the body of the view. If you use @Dependency in a view then the only benefits you get really are the live/preview/test value, but you do not get the ability to dynamically change the dependencies.

We were able to solve this problem for model obj…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dafurman
Comment options

Answer selected by dafurman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants