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

Support for optional values #17

Open
lucianomarisi opened this issue Mar 24, 2017 · 2 comments
Open

Support for optional values #17

lucianomarisi opened this issue Mar 24, 2017 · 2 comments
Labels

Comments

@lucianomarisi
Copy link

Does configen support optional values? for example can we declare String? in the mapping file. The reasoning for this is that some environments don't need all the properties.

@samdods
Copy link
Contributor

samdods commented Mar 28, 2017

Well, no, it's not supposed to. It specifically defeats the purpose of the tool, which is robustness.

But I think there is a way to beat the system if you really want to. Configen supports any type, which is how it allows enums such as, for example, LogLevel for which the value may be defined in the property list as .warning, .error, etc. This means you could define your type as String? and enter the value in the mapping file as nil or "some value" (note you need to provide the quotes in this case, because the value gets printed as is to the .swift source file.

I haven't tried this, and I wouldn't recommend it. You're better off defining the type as String and providing a value even where you don't need it. For example, in the case of a string, provide an empty string and in code only use it if non-empty. At least then it sticks out as missing in the environments that do rely on it.

@KaneCheshire
Copy link
Contributor

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

No branches or pull requests

3 participants