Dear fellow developers,
I use custom compiler flags to distinguish if my app is build for test or for production:
#if PROD
hostname = "foo"
#else
hostname = "bar"
#endif
I added the relevant compiler flag to the target, e.g. under "Swift Compiler - Custom Flags" I added "-D" "PROD".
This works when running the app.
The Problem: Compiler Flags seem to ignored for test code
I created a TestTarget and associated with the target above. When I create a unit test I wrote the following in my test code
#if PROD
XCTAssertEqual(sut.hostname, "foo")
#else
XCTAssertEqual(sut.hostname, "bar")
#endif
The test case will always validate for "bar", i.e. the compiler ran into the else-case. The Swift Compiler Flags for the target are ignored, when compiling the test class itself - so it seems.
The test target configuration does not show fields for changing the Swift Compiler Flags (in contrast to the settings Apple LLVM 7.1 - Preprocessing).
Am I missing something? Am I supposed to add the Swift Compiler Flags as custom fields to my test target?
Kind regards,
Alexander