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

Prevent using the initializer with default parameter for optional values #122

Open
sindresorhus opened this issue Nov 17, 2022 · 1 comment

Comments

@sindresorhus
Copy link
Owner

There's no way to prevent it today, but maybe when Swift supports macros or constant expressions.

I have seen many users do:

static let interval = Key<Double?>("interval", default: nil)

The default parameter is moot in this case.

Or even worse:

static let interval = Key<Double?>("interval", default: 4)

Which has the incorrect behavior by never allowing the value to be set to nil. (The correct solution to this is #54)

@sindresorhus
Copy link
Owner Author

I wonder if we could use a macro to detect this and issue a warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant