ios - 为什么我的 DEBUG 预处理器宏没有被识别 objective-c

标签 ios objective-c xcode macros c-preprocessor

我接手了一个项目,该项目有多种构建方案:演示、发布、调试和生产。整个代码..有几个预处理器宏 if 语句即

#ifdef DEMO
static NSString *const URL_SMART_TAXI      = @"http://demo.theapp.com";
#elif  PRODUCTION
static NSString *const URL_SMART_TAXI      = @"http://prod.theapp.com";
#elif  DEBUG
static NSString *const URL_SMART_TAXI      = @"http://localhost:8000";
#else
static NSString *const URL_SMART_TAXI      = @"http://dev.theapp.com";
#endif

出于某种原因,当我使用演示 方案或生产 方案构建时,这总是有效..但它不适用于调试(每当我更改方案并运行调试时..它总是跳过调试并选择通配符选项)..

我查看了整个项目,没有看到任何针对调试的演示或生产给予的特殊处理。

如果我运行 grep -nri %environment% * 结果如下:

grep -nri production *
project.pbxproj:2767:               84380FEB1705D3E40085487D /* Production */ = { 
project.pbxproj:2797:                       name = Production;
project.pbxproj:2799:               84380FEC1705D3E40085487D /* Production */ = { 
project.pbxproj:2832:                                       "-DPRODUCTION",
project.pbxproj:2846:                       name = Production;
project.pbxproj:3013:                               84380FEB1705D3E40085487D /* Production */, 
project.pbxproj:3024:                               84380FEC1705D3E40085487D /* Production */, 
xcshareddata/xcschemes/theApp.xcscheme:47:      buildConfiguration = "Production"

grep -nri demo *
project.pbxproj:2685:               6314932116E4F7D000B351CA /* Demo */ = { 
project.pbxproj:2715:                       name = Demo;
project.pbxproj:2717:               6314932216E4F7D000B351CA /* Demo */ = { 
project.pbxproj:2751:                                       "-DDEMO",
project.pbxproj:2765:                       name = Demo;
project.pbxproj:3012:                               6314932116E4F7D000B351CA /* Demo */, 
project.pbxproj:3023:                               6314932216E4F7D000B351CA /* Demo */, 
xcshareddata/xcschemes/theApp.xcscheme:87:      buildConfiguration = "Demo"

grep -nri debug *
project.pbxproj:2848:               847D410E168CBD3700CE1B96 /* Debug */ = { 
project.pbxproj:2863:                                       "DEBUG=1",
project.pbxproj:2879:                       name = Debug;
project.pbxproj:2912:               847D4111168CBD3700CE1B96 /* Debug */ = { 
project.pbxproj:2955:                       name = Debug;
project.pbxproj:2972:                                       "DEBUG=1",
project.pbxproj:3010:                               847D410E168CBD3700CE1B96 /* Debug */, 
project.pbxproj:3021:                               847D4111168CBD3700CE1B96 /* Debug */, 
xcshareddata/xcschemes/theApp.xcscheme:26:      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
xcshareddata/xcschemes/theApp.xcscheme:27:      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
xcshareddata/xcschemes/theApp.xcscheme:29:      buildConfiguration = "Debug">
xcshareddata/xcschemes/theApp.xcscheme:43:      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
xcshareddata/xcschemes/theApp.xcscheme:44:      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
xcshareddata/xcschemes/theApp.xcscheme:49:      debugDocumentVersioning = "YES"
xcshareddata/xcschemes/theApp.xcscheme:72:      debugDocumentVersioning = "YES">
xcshareddata/xcschemes/theApp.xcscheme:84:      buildConfiguration = "Debug">

有什么想法吗?

更新: + build设置的相关部分

enter image description here enter image description here enter image description here

最佳答案

这是因为您正在执行“#elif”,它不是与“#elifdef”(如果存在这样的事情)。

您应该同时定义 PRODUCTION、DEBUG 和 DEMO,但只将一个设置为“1”,将其他设置为“0”。

关于ios - 为什么我的 DEBUG 预处理器宏没有被识别 objective-c,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23628534/

相关文章:

iOS, bool 变量

iphone - 使用界面生成器设置根 Controller

ios - 变量 NSString anos 使用 NSLocalizedString Xcode

ios - UIAlertView 与 UIAlertController - iOS 8 中没有键盘

ios - 核心数据设计

ios - 如何以编程方式更改 UITableVeiw 的披露指示器的颜色?

objective-c - 自动释放 CFMutableDictionary

ios - 在 MPMoviePlayerController 之上添加 View

ios - Xcode 7.3.1 应用程序提交到 Appstore

ios - 为什么我的属性(property)因调用地点而异?