DEBUG is a macro that is defined only (by default xcode) when you build the debug / development assembly of your project. This will cause any code between the #ifdef DEBUG and #endif lines to not be included during the release build, but they will be compiled and included in the debug / dev / test build.
Example:
#ifdef DEBUG NSLog(@"Hello World!"); #endif
This is what I use in my Project-Prefix.pch (called DEBUGLOG(@"abc %@", someStr); ):
#ifdef DEBUG extern void DBGQuietLog(NSString *format, ...); #define DEBUGLOG(fmt, ...) DBGQuietLog((@"[Line: %d] %s: " fmt), __LINE__, __FUNCTION__, ##__VA_ARGS__); #else #define DEBUGLOG(fmt, ...) #endif #ifdef DEBUG void DBGQuietLog(NSString *format, ...) { if (format == nil) { printf("nil\n"); return; } va_list argList; va_start(argList, format); NSString *s = [[NSString alloc] initWithFormat:format arguments:argList]; printf("%s\n", [[s stringByReplacingOccurrencesOfString:@"%%" withString:@"%%%%"] UTF8String]); [s release]; va_end(argList); } #endif
This prints the console lines (only during debugging) with the line number, class name and method name as follows:
[Line: 36] -[iPhoneAppDelegate application:didFinishLaunchingWithOptions:]: Hello World!
chown
source share