-
I've been using swift dependencies for a bit now and one topic I didn't find covered (apologies if I missed it!) is the best way to handle dependency usage during initialization. The problem specifically being that you can't access self until after init. Below is a simplified example to illustrate what I would like to be able to do but can't:
A workaround for this that I have been using is something along these lines:
I'm curious if anyone else has come up with a better solution or if there is something I am missing here. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You can access the dependency right in the initializer: init(dependencies: Dependencies = .init) {
@Dependency(\.uuid) var uuid
sessionID = uuid()
} |
Beta Was this translation helpful? Give feedback.
You can access the dependency right in the initializer: