Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write debug messages to Xcode output window

I have see this in sample objective c code before, but can't find it now and all the searches come back with irrelivent results.

I want to write debug messages to the Xcode output window. What's the command to do that? Basically like System.Diagnostics.Debug.WriteLine for C#.

like image 977
Tyrel Van Niekerk Avatar asked Feb 23 '12 22:02

Tyrel Van Niekerk


People also ask

How do I display output in Xcode?

If you just want to have the log output display when you run your app then you can go into XCode4 preferences -> Alerts and click on 'Run starts' on the left hand column. Then select 'Show Debugger' and when you run the app the NSLog output will be displayed below the editor pane.

How do I debug print in Xcode?

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) . Check Automatically continue after evaluating actions.

How do I show debug output?

To see the debug output window, in Microsoft Visual Studio, click View, click Other Windows, and then click Output. You can view the debug output in this window only if the debugger is attached to the process that is writing to the output window.

Where does NSLog write to?

NSLog outputs messages to the Apple System Log facility or to the Console app (usually prefixed with the time and the process id).


1 Answers

NSLog(@"Your message here"); 

...should do it.

To include data from variables you can use string formatting, e.g:

NSLog(@"Value of string is %@", myNSString); 

There are a bunch of different string format specifiers, you can look at them here: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html

like image 52
Will Pragnell Avatar answered Sep 22 '22 23:09

Will Pragnell