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

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

问题描述

我习惯于编程和查看日志消息.我知道您曾经能够在调试 Cocoa 应用程序时使用 NSLog() 来跟踪消息.在 iPhone Xcode 开发环境中编码时跟踪"消息的最佳方法是什么?

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?

推荐答案

在 Xcode 中有一种更方便的跟踪日志消息的方法,那就是使用断点操作.

There's a far more convenient way to trace with log messages in Xcode, and that's using Breakpoint Actions.

在您想要添加 printf 或 NSLog 的代码行上,设置断点,然后按住 Control 键单击它并选择编辑断点".在出现的蓝色气泡中,单击右侧的 + 按钮以打开 Breakpoint Actions:替代文字 http://idisk.mac.com/cdespinosa/Public/Breakpoint%20Actions.png

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.

对于调试Objective-C,通常更有用的是从弹出窗口中选择Debugger Command"并输入'po [[object method] method]'来打印Objective-C对象的描述字符串或方法的结果打电话.

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.

这比 NSLog 和 printf 的优点:

Advantages of this over NSLog and printf:

  • 它正在运行.你不必重新编译并重新启动以添加或编辑记录消息.这可以为您节省很多时间.
  • 您可以有选择地启用和禁用它们.如果你学够了从一个,但它的喷涌是干扰,只需取消选中其启用盒子.
  • 所有输出都在您的Mac,从来没有在 iPhone 上,所以你不必下载和解析事后通过日志.
  • 有机会出货控制台喷涌而出在您的应用程序中显着

另请查看讲话"按钮;它非常适合调试看不到调试日志的全屏应用程序.

Also check out the Speak button; it's great for debugging full-screen apps where you can't see the debug log.

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

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