Xcode preprocessing with Custom flags in Swift
2 min readJun 8, 2019
It has been a long time since I became a developer, really enjoy seeking problems and finding a good workflow.
So this post is about the #if
, the preprocessing of the swift.
The famous key to using #if
is the DEBUG
, but what if we just want to test on some case like #if MOCKDATA
, Here are only 4 steps to using that:
- Go to Project page.
- Choose the target to change. In this case, we are in the command line tool project, and we only a target, which is preprocessingDEMO.
- Open the
Build Settings
, right at the top of the project page. Make sure you are doing step 2 the right way. - Find the Column of
Swift Compiler — Custom Flags
, and add the phase and the key you what to set. In this case, we are addingMOCKDATA
in theDebug
condition.
There you go! Now you can use #if MOCKDATA
to test whatever you what.