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?
You can check #ifdef DEBUG, but I would recommend that you do not.
#ifdef DEBUG
Debug Release. , ..
, , Release .... -, - , .
, . . NSUserDefaults.
NSUserDefaults
, .
, - :
/path/to/Myapp.app/Contents/Macos/Myapp -ServerMode Debug
, . 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]];
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