Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In my project I have a customised solution based on <a href="http://iphonedevelopertips.com/cocoa/filename-and-line-number-with-nslog-part-ii.html" rel="nofollow noreferrer">DebugOutput.m</a> This adds the file &amp; line number to the debug output, making it easier to identify where that output text is coming from, while still keeping it brief.</p> <p>I've augmented the standard solution with a debug mask, so that I can switch debugging on and off for particular areas of functionality in my app. In Debug.h, I have</p> <pre><code>typedef enum { kDebugMaskAp- = 1, kDebugMaskXMLParser = 1 &lt;&lt; 1, kDebugMaskNetwork = 1 &lt;&lt; 2, kDebugMaskAnalytics = 1 &lt;&lt; 3, kDebugMaskCache = 1 &lt;&lt; 4, } debugBitMask; #define debugForComponent(mask,format,...) if( currentDebugMask() &amp; mask) [[DebugOutput sharedDebug] output:__FILE__ lineNumber:__LINE__ input:(format), ##__VA_ARGS__] </code></pre> <p>And in Debug.m</p> <pre><code>-(void)output:(char*)fileName lineNumber:(int)lineNumber input:(NSString*)input, ... { va_list argList; NSString *filePath, *formatStr; // Build the path string filePath = [[NSString alloc] initWithBytes:fileName length:strlen(fileName) encoding:NSUTF8StringEncoding]; // Process arguments, resulting in a format string va_start(argList, input); formatStr = [[NSString alloc] initWithFormat:input arguments:argList]; va_end(argList); // Call NSLog, prepending the filename and line number NSLog(@"File:%s Line:%d %@",[((DEBUG_SHOW_FULLPATH) ? filePath : [filePath lastPathComponent]) UTF8String], lineNumber, formatStr); [filePath release]; [formatStr release]; } </code></pre> <p>In the application, calls look something like this:</p> <pre><code>debugForComponent(kDebugMaskApp,@"Request failed - error %@", [error localizedDescription]); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload