I’m writing a Cocoa app in Objective C that’s communicating with a webservice and I want it to connect to a sandbox in debug mode and to the real webservice in release mode. All I need is to change on line of code where an object that holds the configuration gets instantiated (with a different init-message and different parameters).
So how would I swap a line of code for Release or Debug mode?
You could check for
#ifdef DEBUG, but I would recommend you don’t do that.There are a lots of differences between Debug and Release builds. Different compiler optimizations, different sets of symbols, etc…
Invariably, you are going to find yourself in a situation where you want to run the Release build against your sandbox for debugging purposes…. and your debug build against the production webservice because some customer has a problem that only reproduces in Release mode.
So, for that, I’d suggest a user default. See
NSUserDefaults.Note that simple user defaults can be set from the command line.
Thus, you could do something like: