开发者

Changing values based on compile settings

开发者 https://www.devze.com 2022-12-20 10:32 出处:网络
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 wh开发者_

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 wh开发者_如何学Cen 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号