Skip to content
Discussion options

You must be logged in to vote

After struggling with this for a while, I actually figured out a working solution! I found this section of the dependencies documentation that describes uses a private enum key, which I did. Then when I added conformance to DependencyKey:

private enum KeyValueStorageKey: DependencyKey {
    
    static var liveValue = UbiqutiousStorage() as any KeyValueStorage
}

extension DependencyValues {
    
    public var keyValueStorage: any KeyValueStorage {
        get { self[KeyValueStorageKey.self] }
        set { self[KeyValueStorageKey.self] = newValue }
    }
}

I just had to type-cast the underlying concrete implementation to any KeyValueStorage and it worked!

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by thebarndog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant