how to create a breakpoint's log message action in xcode?

前端 未结 3 848
后悔当初
后悔当初 2020-12-28 08:26

Been watching a WWDC video today about new features in xCode 4. They have mentioned that it a good idea to use log message actions on breakpoints along with \"automatically

相关标签:
3条回答
  • 2020-12-28 08:50

    I notice that the edit breakpoints feature, while useful and perhaps modern, does not commit to source control, so does not scale to a team of developers. For this reason, I would say that when working on a team under source control to stick with code-based logging such as NSLog.

    0 讨论(0)
  • 2020-12-28 08:56

    Create a Breakpoint 'Log Message' action. For the log message include something like:

    URL is @(char*) [[userDocumentsURL description] UTF8String]@
    

    Alternatively you can create a breakpoint 'Debugger command' action similar to:

    po [NSString stringWithFormat:@"URL is: %@", userDocumentsURL]
    

    I prefer using breakpoint actions for logging, as it's arguably easier to clear out a bunch of breakpoints than it is to remove NSLogs. A possible downside to using breakpoints in this fashion is that they are significantly slower (during debugging) than a direct NSLog.

    0 讨论(0)
  • 2020-12-28 09:12

    Here is a similar solution using NSLog, which might be fewer characters than the other solutions.

    debugger command using NSlog

    However, unless you add the void like this:

    po (void)NSLog(@"the person name is: %@", p.name)
    

    you will get an annoying "nil" printed out with your log. for example:

    (lldb) po NSLog(@"foo")
     nil
    2013-06-19 14:42:59.025 TheMove[95864:c07] foo
    
    (lldb) po (void)NSLog(@"foo")
    2013-06-19 14:43:10.758 TheMove[95864:c07] foo
    

    If you can live with the nil (I can) it's faster to type and easier to remember just the po

    0 讨论(0)
提交回复
热议问题