Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 639
PrimeSeventyThree Avatar asked Nov 09 '11 03:11

PrimeSeventyThree


People also ask

How do I create a breakpoint in Xcode?

Navigate to a line in your code where you want execution to pause, then click the gutter or line number in the source editor to set a breakpoint. Xcode displays a breakpoint icon to indicate the location. Drag a breakpoint up or down to move it to another location; drag it away from the gutter to remove it.

How do I set a conditional breakpoint in Xcode?

You can set a conditional break point in Xcode by setting the breakpoint normally, then control-click on it and select Edit Breakpoint (choose Run -> Show -> Breakpoints). In the breakpoint entry, there is a Condition column. Now, there are several issues to keep in mind for the condition.

How do I debug print in Xcode?

Print a variable Click the Add Action button and select Debugger Command. Put any print command in a debug console in a text field. Make sure you prefix it with po , e.g., po print(view) .


1 Answers

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.

like image 102
Josh Avatar answered Oct 23 '22 12:10

Josh