如何使用NSLog(@“iPhone模拟器内部”)进行调试? [英] How do I debug with NSLog(@"Inside of the iPhone Simulator")?

查看:125
本文介绍了如何使用NSLog(@“iPhone模拟器内部”)进行调试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我习惯于编程和使日志消息可见。我知道你以前能够使用 NSLog()在调试Cocoa应用程序时跟踪消息。在iPhone Xcode开发环境中编码时,跟踪消息的最好方法是什么?

解决方案

在Xcode中跟踪日志消息,并使用断点操作。



在您试图添加printf或NSLog的代码行上,设置断点,然后按住Control键并单击它并选择编辑断点。在出现的蓝色气泡中,点击右侧的+按钮以打开断点操作:



在此输入您的日志文本。可以在调试器中打印的任何表达式都可以在由@符号分隔时使用。



对于调试Objective-C,通常从弹出菜单中选择Debugger Command并输入'po [[object method] method]'打印描述字符串一个Objective-C对象或方法调用的结果。



确保点击右上角的继续复选框,以便在日志后继续执行。 / p>

在NSLog和printf上的优势:




  • 您不必
    重新编译并重新启动以添加或编辑
    日志消息。这可以节省大量的
    时间。

  • 您可以选择性地启用和
    禁用它们。如果你从一个学习足够的
    ,但它的spew是
    干扰,只要取消选中它的启用
    框。

  • 所有的输出生成你的
    Mac,从不在iPhone上,所以你
    不必下载并通过日志解析

  • 发送控制台的机会



还可以查看Speak按钮;它是伟大的调试全屏应用程序,你不能看到调试日志。


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?

解决方案

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.

这篇关于如何使用NSLog(@“iPhone模拟器内部”)进行调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆