Swift compiler macro / flag for String value alternative -
in objective-c add c flag of -dvar_name=@\"string value\"
, value nsstring *var = var_name
.
how in swift?
an example of defining api host based on current git branch. branch feature1
, should connected https://feature1.example.com
. shell script can find current branch , add c flag. in objective-c can use branch shell script generate api host url.
update
i not asking boolean flags. need pass string value.
update 2
so far can come use build script generate swift class.
update 3
another option add custom keys info.plist. isn't acceptable solution configuration values works.
macros evil. have been abused things , it's not clean solution. have following options (some of them mentioned you).
- info.plist
the simple, easy read , edit. not big configurations.
- your own
.plist
.
easy read , edit (even command line tools before build, see plistbuddy
tool). better bigger configurations.
- auto generated code
your code can contain expression can matched easily, e.g.
let myconfigvalue = "${my-config-value}".
you can replace values using command line tools, e.g. sed
. replicates macros without using c preprocessor. not clean usable if have build system don't want change.
- multiple code variants
you can have swift file configuration constants , use #if
switch between them.
Comments
Post a Comment