[英]Handling command-line options with the preprocessor in Xcode
我想根據傳遞給xcodebuild
的命令行參數在我的Xcode項目中設置變量的值。
例如,我想運行xcodebuild -project MyProj.xcodeproj -alltargets -configuration Debug ENV=2
並讓它在我的代碼中設置一個名為“rootUrl”的字符串。
我期待在我的代碼中類似於以下內容:
#if (ENV == 2)
static NSString * const rootUrl = @"staging.url.com";
#elif (ENV == 1)
static NSString * const rootUrl = @"dev.url.com";
#else
static NSString * const rootUrl = @"prod.url.com";
#endif
但無論ENV
傳入xcodebuild
的價值如何, rootUrl
總是設置為“ rootUrl
”。
我還在Build Settings的預處理器宏中設置了ENV=$(ENV)
。
我怎樣才能達到理想的行為?
嘗試在命令行上用GCC_PREPROCESSOR_DEFINITIONS="ENV=2"
替換ENV=2
。 我認為你不需要在Build Settings中設置'Preprocessor Macros',因為它無論如何都會被覆蓋。
請參閱xcodebuild - 如何定義預處理器宏? 欲獲得更多信息。
如果我沒記錯的話,那就是你想要的-D標志..它指定預處理器宏..所以-DENV=2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.