Question about the SwiftPM compilation conditions behavior


I have a question about whether a behavior of SwiftPM(or Xcode) is correct or not. When a swift package use compilation conditions like "# if DEBUG" in the source code, I think a user of the package like a Xcode project can not inject its compilation conditions to the package from its project configuration, but I observed that the package's conditions work when the condition's name is prefix matched to the project configuration name. Does it correct?


  1. Create a swift package.
  2. Implement # if DEBUG #else #endif.
  3. Create some Xcode project.
  4. Setup dependency to the package.
  5. Add breakpoints to the condition branches.
  6. Create another configuration named "Test".
  7. Set "DEBUG" compilation conditions to the "Test" configuration.
  8. Run with "Debug" configuration, and DEBUG branch will be executed.
  9. Run with "Test" configuration, and DEBUG branch will not be executed.

If you make a configuration which named "Debug2" or "DebugFooBar", the # if DEBUG branch will be executed.

Terms of Service

Privacy Policy

Cookie Policy