当前位置: 动力学知识库 > 问答 > 编程问答 >

iphone - Changing values based on compile settings

问题描述:

Is there a way to create an if statement based on compile settings? I have an App that accesses a web-based API and when compiling in debug mode I want it to use the private beta version but when I compile for release I want it to use the public live version of the API.

At the moment I just have a NSString holding the url address.

网友答案:

Typically for this sort of thing you would use a preprocessor directive:

#ifdef DEBUG_MODE
    // connect to beta version
#else
    // connect to live version
#endif

You can either define your own DEBUG_MODE symbol, or you can use an existing one (I'm not sure what it might be called for the iPhone SDK).

网友答案:

To extend on Greg's answer, you can pass the compiler flag -DDEBUG_MODE (or -D[any name here]) to define DEBUG_MODE and cause the first branch of the #ifdef to be compiled.

分享给朋友:
您可能感兴趣的文章:
随机阅读: