You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, let's say I have an app where the user brings their own OpenAI key by inputting it in a TextField, and my dependency should use that key to call OpenAI endpoints.
pointfreeco website code uses an EnvVars dependency, but in that case the secret and dependency is defined inside the application. I want to make this OpenAI dependency a library, that's why I can have no idea where the library users put the API key.
In the view, the changes made to TextField for the api key are saved to UserDefaults.
I thought about overriding thatSecrets dependency when creating the ObservableObject. But it only works the first time it's called. I believe it caches it and it never calls UserDefaults.standard.string again, which I log with the print function in the next line.
The solution seems to be adding API key as argument to every variable of the dependency, but it didn't look right. I read about resetting the cache with $0 = DependencyValues(), but it also seems to be a one-time operation.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello, let's say I have an app where the user brings their own OpenAI key by inputting it in a TextField, and my dependency should use that key to call OpenAI endpoints.
pointfreeco website code uses an
EnvVars
dependency, but in that case the secret and dependency is defined inside the application. I want to make this OpenAI dependency a library, that's why I can have no idea where the library users put the API key.Here is an example attempt. I'm trying to make a library using swift-openapi-generator.
I defined a
Secrets
dependency to be used in OpenAI dependency.In the view, the changes made to
TextField
for the api key are saved toUserDefaults
.I thought about overriding that
Secrets
dependency when creating the ObservableObject. But it only works the first time it's called. I believe it caches it and it never callsUserDefaults.standard.string
again, which I log with theprint
function in the next line.The solution seems to be adding API key as argument to every variable of the dependency, but it didn't look right. I read about resetting the cache with
$0 = DependencyValues()
, but it also seems to be a one-time operation.How should we do it?
Beta Was this translation helpful? Give feedback.
All reactions