Dependent dependency

There is some common case when only after login you can use some API, so this class/struct dependents from some "logged in"-data and I want to create DependencyValues with this ApiClass, but I can't make "global"-initializer.
Also, I can't find any samples under "Point-Free · GitHub"

So, question, how can I do that? maybe someone have a samples.
Thank you.

Hi @Anatolii ! You can look at LoginCore feature within the Tic-Tac-Toe example project in the swift-composable-architecture repository. I hope it can help you!

Thank you for response, I saw it, but it not suitable for me, not answering on question how to build dependent dependency

@Anatolii what do you mean by "dependent dependency"?


ApiClient(account: Account)
Account - not equitable

after auth I got Account and want to use:
@Dependency(.apiClient) var apiClient

@Anatolii I see, you maybe want to conform your type with the DependencyKey protocol, like this: swift-composable-architecture/LiveAuthenticationClient.swift at main · pointfreeco/swift-composable-architecture · GitHub then extending the DependencyValues to add your dependency, like this: swift-composable-architecture/AuthenticationClient.swift at main · pointfreeco/swift-composable-architecture · GitHub

1 Like

Thank you, @otondin
Will try