why type of Key class must be generic?

#17 · closed · 2 comments

View on GitHub ↗

muhasturk

We have to define generic type of every Key instance but I do not get it. first parameter of 'save' method 'value' already knows what generic type is gonna be saved. Is it possible to improve Key class which is gonna not be required to define what generic type is? What I mean: ```swift let object = Person(n: "Mustafa") Defaults.shared.set(object, Key("admin") ``` we can get the type of object variable.

Comments

nmdias

Hi @muhasturk You would have to use Key<T> to get that same object either way. I guess it makes sense to reuse the Key for both getting and setting. Otherwise you would use a Key<T> to get the correct object's type, but then only use a string to set it, thus needing to define key twice somewhere in code. 🤔

muhasturk

Now I see. We need to declare type of Key, because of get function. You can close issue. Thanks for participation.