Is it possible to have a macro defined in (testing) target settings or in the testing .pch file such that it's passed to the entire app?
Or is there any macro already available to check (from code) if we're running a test?
e.g.:
#if TEST=1
// do something
#else
// do something else
#endif
The reason that I want this is to skip some code, asserts etc. during testing (without having to change a #define in the main app .pch each time I run tests).
Thanks.
It looks like you can do this in a very similar way to Objective-C. The swift compiler takes the -D command switch. To adapt this to testing I defined the Literal I wanted only in the Test Target Build settings.
Instructions:
Build settings for the Test Target ->
Swift Compiler Custom Flags ->
-DTEST (yes, including the -D prefix)
Enables this code:
// Objective-C and Swift
#if TEST
// Test only code version code
#else
// App only code
#endif
I found the solution at this article on transitioning to swift.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With