Preprocessor macros in Xcode with Swift
I'm having trouble reproducing in Swift the Macro Preprocessor feature offered by ObjC. I've heard that Swift doesn't have a preprocessor, so I'm looking for another way to implement this.
My ultimate goal is to build my project using command line tools, passing in a custom variable and value that will be preprocessed and inserted into the code at specific points before the build is done.
This is the solution for ObjC:
Use this command to run the test:
xcodebuild \
test \
-scheme TestUserDefinedVariablesObjC \
-destination 'platform=iOS Simulator,name=iPhone 6' \
MY_VAR=42
I am using MY_VAR
in code like this:
int a = MY_VAR;
(I add in MY_VAR preprocessor macros in their target build settings, for example MY_VAR=$(MY_VAR)
)
As a last resort, I could add a pre-action to the Run schema that replaces the correct values ββwith sed or something, but that's not a great solution.
source to share