Skip to content

When should withDependencies(from: self) be used? #49

Answered by tgrapperon
Zeta611 asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @Zeta611. I agree that this can be a little confusing. Maybe some insight about the internals could make things clearer:

  • When a @Dependency property wrapper is initialized, it internally captures the complete set of current DependencyValues, independently of the KeyPath it observes. This is not a general property of property wrappers, but something that was implemented on purpose. When a model instance is initialized, all its @Dependency property wrappers values (the _ values) are initialized. @Dependency is able to init itself from the KeyPath only, and that's why you don't need to pass a default value, and you don't see it, but it happens right before the model's init.
  • withDependen…

Replies: 1 comment 1 reply

Comment options

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

Answer selected by Zeta611
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