@TinyStorageItemSet: New property wrapper to retrieve from all keys of a type, as a dictionary - #13
Open
Mohamad-Kredly wants to merge 4 commits into
Open
Conversation
…ues for the keys matching the specified key type in a specified storage, as a dictionary of [Key: ValueType] - New protocol TinyStorageBuildableKey to specify that a type could be rebuilt from a string raw value - Value type must be equatable as to identify what changed in the dictionary, on set * String as a key is not supported as it would fetch all keys which goes against the use case of this propety wrapper
…igrating from UserDefaults" to its own section
Owner
|
Very cool idea! I'm gonna leave this up as a PR because it feels slightly out of scope of what I'm envisioning for this library, but leaving it up as I think this is a cool use case that someone else may benefit from! Great work |
Author
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use case
Having a String enum conforming to
TinyStorageKey, I wanted to access all of the stored value for the possible keys in one place instead of having to use aTinyStorageItemwrapper for every case and possibly miss some as I update the code.What's new
This PR introduces two main things:
TinyStorageBuildableKey: Protocol to initialize a conforming type from a String raw value, if possible.@TinyStorageItemSet: A property wrapper for a dictionary of Key conforming to the a new protocol and Type of Codable, Sendable, and Equatable. Note that String is not supported as a key as it would include all possible keys which goes against the use case described here.Updates to README:
Usage