Ios 为什么不是';t正在识别我的调试预处理器宏objective-c
我接手了一个有几个构建方案的项目:演示、发布、调试和生产。在整个代码中。。有几个预处理器宏if语句Ios 为什么不是';t正在识别我的调试预处理器宏objective-c,ios,objective-c,xcode,macros,c-preprocessor,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 NSStri
#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">
有什么想法吗
更新:+生成设置的相关部分
这是因为你在做“
#elif
”,这与“#elifdef
”(如果存在这样的事情)不一样
您应该同时定义生产、调试和演示,但只将其中一个设置为“
1
”,将其他设置为“0
”那么,当我使用#elif
进行生产时,它为什么工作得很好呢?@Michael说得对,您不应该将#ifdef
与#elif
混用,但我认为您的实际问题是在DEBUG=1
之前缺少-D
。因为您可能正在执行“#定义生产1
”,并且由于在为生产构建时根本没有定义调试,因此它与您正在执行的“#if PRODUCTION
”匹配。编译时会变成“\if 1
”。@PaulR好的,伙计们,我觉得你们说的话很有价值。。但是我还是有点困惑。。我用构建设置的相关部分更新了我的问题。。这是否使我的情况更清楚了?如果这是我的项目,我可能会在预处理器宏行中添加“DEMO=0 PRODUCTION=0
”,该行显示“DEBUG=1
”。然后将“#ifdef
”更改为“#if
”。现在有意义了吗?你在DEBUG=1
之前缺少了-D
-它应该是-DDEBUG=1
。额外的D
的目的是什么?它是定义宏的命令行开关-用于生产和演示,但是在DEBUG的情况下它就丢失了。@paurr but DEBUG=1是在我的发行版方案中定义的。。我从来没用过。。我应该把-DNS\u BLOCK\u断言=1-DDEBUG放在其他C/C++标志下吗?但似乎和我想做的事情无关。。这两件事是完全不同的。。