Various / config codes in Release & Debug (Obj-C) assembly

I am writing a Cocoa application in Objective-C that communicates with a web service, and I want it to connect to the sandbox in debug mode and to the real web service in release mode. All I need to do is change the line of code where the object containing the configuration receives an instance (with a different init message and various parameters).

So, how would I change the line of code for Release or Debug mode?

+5
source share
3 answers

You can check #ifdef DEBUG, but I would recommend that you do not.

Debug Release. , ..

, , Release .... -, - , .

, . . NSUserDefaults.

, .

, - :

/path/to/Myapp.app/Contents/Macos/Myapp -ServerMode Debug
+7

, . Xcode. - :

#if DEBUG_MODE
#define BACKEND_URL @"http://testing.myserver.com"
#else
#define BACKEND_URL @"http://live.myserver.com"
#end

NSURLRequest *myRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:BACKEND_URL]];
+8

First, determine the preprocessor symbol, which is installed only in your Debug assembly configuration, in accordance with question 367368 - call it, say, DEBUG. Then you can do

#ifdef DEBUG
  // Code that only compiles in debug configuration
#else
  // Code that compiles in other configurations (i.e. release)
#endif
+2
source

All Articles