theappbusiness / ConfigGenerator

Configuration file code generator for use in Xcode projects
MIT License
157 stars 19 forks source link

Support for optional values #17

Open lucianomarisi opened 7 years ago

lucianomarisi commented 7 years ago

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 commented 7 years ago

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 commented 6 years ago

Issue #17: Support for optional values