Skip to content

Best Practices for nested function calls in dependencies #96

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

You must be logged in to vote

Yes, you can do that, but you have to be aware of all the caveats of using @Dependency in an escaping closure like that, unless you are using a single-entry point system such as the Composable Architecture.

Here are some articles from the docs for you to learn about these subtleties:

I personally think using a helper function to share the logic is better, and avoids the caveats detailed in the above articles.

There's also a chance that a protocol version of this dependency is a better fit since…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@alinless
Comment options

@mbrandonw
Comment options

Answer selected by alinless
@alinless
Comment options

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