PrimeSeventyThree
PrimeSeventyThree

Reputation: 940

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

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 continue after evaluation actions" enabled to output a variable's value for instance instead of using NSLogs all the time.

lets say I have something like that:

NSLog(@"URL is : %@", userDocumentsURL);

How would I write a log message action to display userDocumentsURL's value? Is it really a good idea to use the above method instead of NSLog?

Upvotes: 15

Views: 14042

Answers (3)

Skotch
Skotch

Reputation: 3091

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

Upvotes: 22

Barton Friedland
Barton Friedland

Reputation: 23

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.

Upvotes: -4

Josh
Josh

Reputation: 695

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.

Upvotes: 28

Related Questions