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

Tyr*_*erk 31 xcode objective-c ios

我之前在示例目标c代码中看到了这一点,但现在无法找到它,并且所有搜索都以不可靠的结果返回.

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

Wil*_*ell 51

NSLog(@"Your message here");
Run Code Online (Sandbox Code Playgroud)

......应该这样做.

要包含变量中的数据,可以使用字符串格式,例如:

NSLog(@"Value of string is %@", myNSString);
Run Code Online (Sandbox Code Playgroud)

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


sch*_*sch 9

你在找NSLog.调用

NSLog(@"Message");
Run Code Online (Sandbox Code Playgroud)

Message在控制台上打印.

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

NSLog(@"This is a string: @", aString);
NSLog(@"This is an int: %d", anInt);
Run Code Online (Sandbox Code Playgroud)


小智 5

最好使用调试器断点编写调试消息,而不是使用NSLog消息来混淆代码.断点还可以避免在发布应用程序时删除所有这些日志消息.

要执行此操作,请在Xcode中设置断点,双击它,然后单击弹出窗口中的"添加操作"按钮.选择"日志消息"并键入您的消息.选中底部的"评估后自动继续"复选框,以防止在断点上暂停执行