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.

+3


source to share


1 answer


Are you using a keyboard or keyboard? If yes, check "

Example: The preprocessor macros in my setup My_var = \ "42 \"



check ". Change it with this

0


source







All Articles