ios 将调试消息写入 Xcode 输出窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9422671/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 17:00:36  来源:igfitidea点击:

Write debug messages to Xcode output window

objective-ciosxcode

提问by Tyrel Van Niekerk

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.

我之前在示例目标 c 代码中看到过这个,但现在找不到它,所有搜索都返回无关紧要的结果。

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#.

我想将调试消息写入 Xcode 输出窗口。这样做的命令是什么?基本上就像 C# 的 System.Diagnostics.Debug.WriteLine。

回答by Will Pragnell

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

有很多不同的字符串格式说明符,你可以在这里查看它们:https: //developer.apple.com/library/content/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html

回答by sch

You are looking for NSLog. Calling

您正在寻找NSLog. 打电话

NSLog(@"Message");

will print Messageon the console.

将打印Message在控制台上。

See herefor more info about how to use string formatters to print the values of variables like in the examples below:

有关如何使用字符串格式化程序打印变量值的更多信息,请参见此处,如下例所示:

NSLog(@"This is a string: @", aString);
NSLog(@"This is an int: %d", anInt);

回答by StevenHolland

It's better to write the debug messages using debugger breakpoints instead of cluttering your code with NSLog messages. Breakpoints will also save you from having to remove all those log messages when you ship your app.

最好使用调试器断点编写调试消息,而不是用 NSLog 消息使代码混乱。断点还可以让您在发布应用程序时不必删除所有这些日志消息。

To do this, set a breakpoint in Xcode, double-click on it, and click the Add Action button in the pop-up window. Select "Log Message" and type your message. Check the "Automatically continue after evaluating" check box at the bottom to keep it from pausing execution on the breakpoint

为此,在 Xcode 中设置一个断点,双击它,然后单击弹出窗口中的 Add Action 按钮。选择“日志消息”并键入您的消息。选中底部的“评估后自动继续”复选框,以防止它在断点处暂停执行