bool kDebuggingEnabled = NO;
...
for(i=0; i<length; i++){
...
if (kDebuggingEnabled) {
NSLog (@"Value of variable # %i",$resultingOptions);
}
}
whenever my app is live, my code checks the condition every time regarding NSLog.
Is there any better way to improve performance of my code?
You could use preprocessor macros to turn logging on and off. A good example is the
DLogmacro from Marcus Zarra on the Cocoa is My Girlfriend blog.You would place the above in your prefix.pch file and then simply replace
NSLogstatements withDLogstatements. You also need to make sure thatDEBUGis set in your debug build configuration.Using preprocessor macros like this means that the logging code does not get compiled into your release build so there is no performance hit for the log statements.
The blog post also contains some other useful macros for handling assertions.