Swift Flag & Build

最近得弄,針對同一個 APP,有著不同的資源配置。

目前想要實作的方式為:

  1. 設定 Configuration
  2. 再設定 Swift Flag
  3. 程式碼實作
  4. command line build

1. 設定 Configuration

先從 Debug Duplicate 出 Debug2


2. 再設定 Swift Flag

設定 Swift Flag 我們分別設定 D1 及 D2(設定時要多個 -D)


3. 程式碼實作

接著就可以開始寫類似 C Macro 的東西

1
2
3
4
5
#if D1
print("Hello, World! 1")
#elseif D2
print("Hello, World! 2")
#endif

4. command line build

build
run

1
2
xcodebuild -configuration Debug
build/Debug/S22

Reference

How can I build for release/distribution on the Xcode 4?
In absence of preprocessor macros, is there a way to define practical scheme specific flags at project level in Xcode project
Transitioning from Objective-C to Swift