NSLog 不打印到控制台

发布于 2024-12-11 16:59:30 字数 254 浏览 1 评论 0原文

我有一个 Xcode 项目,我已经工作了几个月了。我从来没有遇到过 NSLog 问题,但升级到 Xcode 4.2 后,控制台上不会记录任何内容。我什至尝试将其扔到 viewDidLoad: 中

    - (void)viewDidLoad
{
    [super viewDidLoad];

    NSLog(@"Can anyone hear me?");

,但什么也没有。还有其他人遇到这个问题或知道解决方案吗?

I have an Xcode project I've been working on for months. I've never had a problem with NSLog, but after upgrading to Xcode 4.2 nothing will log to the console. I even tried throwing this in viewDidLoad:

    - (void)viewDidLoad
{
    [super viewDidLoad];

    NSLog(@"Can anyone hear me?");

And nothing. Is anyone else having this problem or know a solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

深居我梦 2024-12-18 16:59:30

嗯,这很尴尬。控制台不知何故被停用,我实际上正在观察变量窗口。按 Shift + + C 就可以了。

非常感谢 Robert King 在这个帖子上的发言:

https://devforums.apple.com/message/565880 #565880

Well, this is embarrassing. The console got deactivated somehow and I was actually watching the variables window. Pressing Shift + + C did the trick.

Many thanks to Robert King on this thread:

https://devforums.apple.com/message/565880#565880

檐上三寸雪 2024-12-18 16:59:30

这是Xcode8 + iOS10的一个bug,我们可以这样解决:

模拟器上,添加Name OS_ACTIVITY_MODE和Value
变量禁用并检查它(产品 -> 方案 -> 编辑方案 -> 运行 -> 参数 -> 环境)。
在此处输入图像描述

设备上时,仅添加OS_ACTIVITY_MODE并勾选(不添加Value)。您将在 Xcode8 控制台中看到 NSLog。
在此处输入图像描述

This is a bug of Xcode8 + iOS10, we can solve it in this way:

When on simulator, add the Name OS_ACTIVITY_MODE and the Value
Variables disable and check it (Product -> Scheme -> Edit Scheme -> Run -> Arguments -> Environment).
enter image description here

When on device, only add OS_ACTIVITY_MODE and check it(don't add the Value). You'll see the NSLog in the Xcode8 Console.
enter image description here

作妖 2024-12-18 16:59:30

在iOS10中,很多系统日志记录都显示在控制台上。可以通过在方案的运行参数中包含 OS_ACTIVITY_MODE = 禁用来禁用此功能。

但是对于 iOS10,将不再显示 NSLog 消息。
在较低的 iOS 版本中,消息仍会显示。因此,也许对于大多数测试用例,您可以使用较低的 iOS 版本。

否则,您可以包含一个 Swift 函数来打印(打印函数)您的文本,这在 iOS10 中工作正常。

在iOS10.0.2和iOS9.3上测试

In iOS10, a lot of system logging is displayed on the console. This can be disabled by including the OS_ACTIVITY_MODE = disabled in the Run Arguments for your scheme

However for iOS10, NSLog messages will not be displayed anymore.
In lower iOS versions the messages will still be displayed. So maybe for most test cases you can use a lower iOS version.

Otherwise you can include a Swift function which prints (print function) your text, this is working okay in iOS10.

Tested on iOS10.0.2 and iOS9.3

笑咖 2024-12-18 16:59:30

我的问题是我选择了调试器输出。一旦我将其更改为所有输出目标输出,NSLogs 就会显示正常。

如果这让您感到困惑,它位于调试区域的左侧。

My issue is that I have Debugger Output selected. Once I changed it to either All output or target output NSLogs appear fine.

In case this confuses you its on the left of the Debug area.

薄凉少年不暖心 2024-12-18 16:59:30

我有同样的问题。
诀窍是从项目中搜索并删除下面提到的行。

  #define NSLog(...)

搜索整个项目并将其删除。

I had the same issue.
The trick is to search and remove the below mentioned line from the project.

  #define NSLog(...)

Search the entire project and remove it.

謸气贵蔟 2024-12-18 16:59:30

我刚刚经历过这个,所以还有一件事需要检查。

->确保您没有在日志输出下方的过滤器字段中输入任何内容。因此,就我而言,我在记录器中搜索一个术语,却忘记从“过滤器”文本字段中删除搜索到的术语。卫生部!

I just experienced this, so here's another thing to check.

-> Make sure you don't have anything typed in the Filter field below the Log Output. So, in my case I was searching for a term in the logger and forgot to delete the searched terms out of the Filter text field. DOH!

绳情 2024-12-18 16:59:30

我的问题是我不小心切断了应用程序委托(委托 - 文件所有者)的引用出口。

My issue was that I'd accidentally severed the referencing outlet from App Delegate (delegate - file's owner).

梦中楼上月下 2024-12-18 16:59:30

升级到 macOS 的 Xcode 15.0.1 后,也出现了类似的问题。 NSLog 未打印到控制台。对我有用的这个问题的解决方案如下所述。请参阅https://lapcatsoftware.com/articles/2023/10/5.html< /a> , https://developer.apple.com/forums/thread/742594 了解更多信息。

  1. 在“产品”->“方案”->“编辑方案”->“运行”->“参数”下,添加
    带有键“IDELogRedirectionPolicy”的环境变量价值
    “oslogToStdio”
  2. 在产品->方案->编辑方案->运行->选项下,设置
    控制台到“Xcode”或“终端”

This similar issue was observed after upgrade to Xcode 15.0.1 for macOS. NSLog was not printing to console. The solution to this issue that worked for me is as mentioned below. Refer to https://lapcatsoftware.com/articles/2023/10/5.html , https://developer.apple.com/forums/thread/742594 for more info.

  1. Under Product->Scheme->Edit Scheme->Run->Arguments, add an
    environment variable with key "IDELogRedirectionPolicy" & value
    "oslogToStdio"
  2. Under Product->Scheme->Edit Scheme->Run->Options, set
    the console to "Xcode" or "Terminal"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文