How to determine configuration in Swift code using Swift Package Manager

I am creating an application using the Swift Package Manager, and I need to know in what configuration the project was built, i.e. Debugor Release. I try to stay away from using the file .xcodeproj. Please let me know if possible. I will insert a simple example below, but just know if there is a better way to handle the configuration, besides the code below, please send as an answer.

Example:

// main.swift

#if DEBUG
  print("Im in Debug!!")
#else
  print("Im in Release!!")
#endif
+4
source share
1 answer

Swift 3.1 Package.swift ( Swift 4). -Xswiftc swift build swift test.

DEBUG , swift build :

swift build --configuration debug -Xswiftc "-D" -Xswiftc "DEBUG"

:

swift build --configuration release

-Xlinker Xcc C .

+6

Source: https://habr.com/ru/post/1674510/


All Articles