How do I debug with NSLog(@“Inside of the iPhone Simulator”)?

NSLog :) The output is piped to the console window in Xcode and the log files on the iPhone (which are viewable through the Xcode device manager).

1 Beautiful, thanks! – Rob Sawyer Feb 17 '09 at 20:33 12 Just for reference, you can access the console by Run > Console, or Shift+Command+R – Jeff Winkworth Aug 15 '09 at 17:53 upvote to give @cdespinosa the well earned populist badge. – Nikolai Ruhe Sep 22 '09 at 8:52 @Andrew Grant, can you add the @Jeff Winkworth comment to your answer to make it complete?

– Yar Feb 27 '10 at 13:58 1 Shift+Command+Y for Xcode 4 – pablasso Jul 8 at 15:48.

There's a far more convenient way to trace with log messages in Xcode, and that's using Breakpoint Actions. On the line of code where you'd be tempted to add a printf or NSLog, set a breakpoint, then control-click it and choose "Edit Breakpoint". In the blue bubble that appears, click the + button on the right to open the Breakpoint Actions: Enter your log text there.

Any expression that can be printed in the Debugger can be used when delimited by @ signs. For debugging Objective-C it's generally more useful to choose "Debugger Command" from the popup and enter 'po object method method' to print the description string of an Objective-C object or the result of a method call. Make sure to click the "Continue" checkbox at the top right so execution continues after the log.

Advantages of this over NSLog and printf: It's on the fly. You don't have to recompile and restart to add or edit log messages. This saves you a lot of time.

You can selectively enable and disable them. If you learn enough from one, but its spew is interfering, just uncheck its Enabled box. All the output is generated on your Mac, never on the iPhone, so you don't have to download and parse through logs after the fact.

The chance of shipping console spew in your application is significantly decreased. Also check out the Speak button; it's great for debugging full-screen apps where you can't see the debug log.

3 Give him a Populist for this one! – fbrereto Sep 3 '09 at 23:35 19 There's one more advantage which, in my opinion, is the best of all: When developing in a team (using SCM), I hate to have my console cluttered with debugging output of other developers. Using your method, debugging output is not committed to the source code or project and will only be seen on the local machine where it was created.

– Nikolai Ruhe Sep 22 '09 at 8:18 6 I don't get how to use it. Please give an example equivalent to NSLog(@"x %f",myView.center. X); – Allisone Jun 11 '10 at 16:03 1 Is there a way to log without stopping at the breakpoint, as you would with NSLog?

– Luke Jul 9 '10 at 18:40 1 I like this idea and I think I'll use it from time to time. But I see a big disadvantage as well - It's too easy to wipe, and although there is a comment saying that seeing logging from other developers is a minus, I think exactly the opposite. There is a huge advantage to have built in logging that helps you trace program execution that stays with the code and is not wiped by removing all break points or giving the code to another developer.

For this sort of logging, defines are your friend. – drekka Jan 16 at 11:32.

Here's a great bit of code I picked up somewhere on the web. It defines new functions DLog() and ALog(). DLog messages only appear when the app is compiled with a -DDEBUG flag (define DEBUG).

ALog messages ALWAYS appear (even in Release mode). // DLog is almost a drop-in replacement for NSLog // DLog(); // DLog(@"here"); // DLog(@"value: %d", x); // Unfortunately this doesn't work DLog(aStringVariable); you have to do this instead DLog(@"%@", aStringVariable); #ifdef DEBUG # define DLog(fmt, ...) NSLog((@"%s Line %d " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); #else # define DLog(...) #endif // ALog always displays output regardless of the DEBUG setting #define ALog(fmt, ...) NSLog((@"%s Line %d " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__).

I've used this in the past and it worked well for me at the time...You just have to make sure you have "other C flags" defined for "-DDEBUG", "-DRELEASE", etc. – Ari Braginsky Dec 9 '10 at 1:42 There's plenty of example code around using defines like this. The advantage to doing so is that with a simple preprocessor setting in your debug build you can have a whole trace of you code appear in the logs. – drekka Jan 16 at 11:30.

In my project I have a customised solution based on DebugOutput. M This adds the file & line number to the debug output, making it easier to identify where that output text is coming from, while still keeping it brief. 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 typedef enum { kDebugMaskAp- = 1, kDebugMaskXMLParser = 1 FilePath : filePath lastPathComponent) UTF8String, lineNumber, formatStr); filePath release; formatStr release; } In the application, calls look something like this: debugForComponent(kDebugMaskApp,@"Request failed - error %@", error localizedDescription).

Paste this in your prefix header. ALL logs from project will dissappear for sure . #ifndef __OPTIMIZE__ # define NSLog(...) NSLog(__VA_ARGS__) #else # define NSLog(...) {} #endif.

You could use NSLogger which brings a lot more to the table than just logging your messages. I use macros to disable logs in release builds, while leaving every single one of them active in debug builds. The log volume is not an issue, as NSLogger offers powerful log filtering options.

I simply use the replace all functionality.... I disable all my NSLog statements by replacing NSLog(@" with //***NSLog(@" That way I can simply find it (using find in all project files) with //***NSLog(@" and re-enable them Nothing fancy but it works :).

One minor tip for users looking for a Replace All button: There is no Replace All button in Find in Project window, that is because when none of the matches is selected, Replace button does a Replace All. – ustun Oct 14 '09 at 18:46 1 This is a tad dangerous when using Version Control...! – JBRWilkinson Jun 30 '10 at 21:48 This is not really a good idea. It's too easy to forget or get wrong.

And it depends on the developer getting it right every time, not to mention it's a manual task. The best option is to make use of defines as mentioned in another reply. – drekka Jan 16 at 11:28 1 The real danger is if you're the sort to not use { braces } when they're optional.

Then if you comment out the NSLog() invocation (assuming you have a line break before it) you're left with something like "if ( foo ) // NSLog( @"blah" )" which will then make the next code block conditional. (Even #defines can be a concern with this style of coding. ) – Marvo Jan 18 at 0:31 Instead of this, I put my NSLogs in an if statement using constant #defined in .

M file. I can enable/disable logs for a specific . M file--and always check-in to version control with NSLogs disabled.

– bentford Jun 22 at 22:37.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions