Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infer the string key name #2

Closed
sindresorhus opened this issue Apr 11, 2018 · 1 comment
Closed

Infer the string key name #2

sindresorhus opened this issue Apr 11, 2018 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@sindresorhus
Copy link
Owner

We currently have to define the key name twice:

static let key = Defaults.Key<Bool>("key", default: false)

Would be nice if we could infer the string "key" from the static let key name. I've not managed to find a way to do this, but help welcome.

@sindresorhus sindresorhus added enhancement New feature or request help wanted Extra attention is needed labels Apr 11, 2018
@sindresorhus
Copy link
Owner Author

I no longer believe this is a good idea. This would make it possible to accidentally refactor to rename the key and cause data loss.

For example, in my project, I have often come up with a better key name after a while, but I cannot change the internal storage key, so I have something like this:

static let someBetterName = Defaults.Key<Bool>("foo", default: false)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant