I'm used to programming and having log messages be viewable. I know you used to be able to use NSLog()
to trace out messages when debugging Cocoa applications. What is the best way to "trace" messages when coding in an iPhone Xcode development environment?
You'll need to go to Settings > Advanced and check the Show Debug Menu option. Then you'll see the option to open the web inspector for the Simulator right from that menu. With the Web Inspector open, you can debug inside the Simulator just like you could right in a desktop browser with DevTools.
In App Developer Menu On Android emulator, you need to press command + M. Debug JS Remotely − Used for activating debugging inside browser developer console. Enable Live Reload − Used for enabling live reloading whenever your code is saved. The debugger will open at localhost:8081/debugger-ui.
E. In the Safari on your Mac, on the Safari menu bar, choose the "Develop" menu. Scroll to the iOS Simulator option. Select the page for debugging.
You can access the developer menu by shaking your device or by selecting "Shake Gesture" inside the Hardware menu in the iOS Simulator. You can also use the ⌘D keyboard shortcut when your app is running in the iOS Simulator, or ⌘M when running in an Android emulator on Mac OS and Ctrl+M on Windows and Linux.
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: alt text http://idisk.mac.com/cdespinosa/Public/Breakpoint%20Actions.png
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:
Also check out the Speak button; it's great for debugging full-screen apps where you can't see the debug log.
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__);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With