我的 NSLog 输出在哪里?

发布于 2024-10-20 23:35:38 字数 176 浏览 3 评论 0原文

我刚刚开始学习iOS开发。我在代码中使用了一些 NSLog 语句,但它们似乎没有输出到任何地方。我的应用程序正在使用调试配置,并且我正在 Xcode 中的 iPhone 模拟器中运行我的应用程序。我已经检查了 Xcode 控制台(在“运行”菜单下)和 Mac 上的 Console.app,但什么也没有。

可能是什么问题?

I've just started out learning iOS development. I'm using some NSLog statements in my code but they don't appear to be output anywhere. My application is using the debug configuration and I'm running my application in the iPhone simulator from within Xcode. I've checked both the Xcode console (under the Run menu) and also Console.app on my Mac, but there's nothing.

What could be the problem?

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

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

发布评论

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

评论(5

猫烠⑼条掵仅有一顆心 2024-10-27 23:35:38

确保您已激活控制台。为此,您可以:

  • 转至查看>调试区>激活控制台(从菜单栏)
  • 或按键盘上的 C

Make sure you have your Console activated. To do that, you can:

  • Go to View > Debug Area > Activate Console (From your Menu Bar)
  • Or press C on your keyboard
季末如歌 2024-10-27 23:35:38

模拟器上的 NSLog() 输出确实显示在 Console Mac OS X 应用程序中。

转到所有消息,然后根据您的应用名称进行过滤以消除多余信息,然后再次运行。如果在程序执行期间 NSLog 代码实际上被命中,您将在输出中看到它。

NSLog() output on the simulator does indeed show up in the Console Mac OS X application.

Go to All Messages and then filter based on your app name to get rid of the fluff, and run again. You'll see it in your output if the NSLog code is actually being hit during the execution of your program.

我不会写诗 2024-10-27 23:35:38

像这样使用 NSLog()

NSLog(@"The code runs through here!");

或者像这样 - 带占位符:

float aFloat = 5.34245;
NSLog(@"This is my float: %f \n\nAnd here again: %.2f", aFloat, aFloat);

NSLog() 中,您可以像 + (id)stringWithFormat:(NSString *) 一样使用它format, ...

float aFloat = 5.34245;
NSString *aString = [NSString stringWithFormat:@"This is my float: %f \n\nAnd here again: %.2f", aFloat, aFloat];

您也可以添加其他占位符:

float aFloat = 5.34245;
int aInteger = 3;
NSString *aString = @"A string";
NSLog(@"This is my float: %f \n\nAnd here is my integer: %i \n\nAnd finally my string: %@", aFloat, aInteger, aString);

Use NSLog() like this:

NSLog(@"The code runs through here!");

Or like this - with placeholders:

float aFloat = 5.34245;
NSLog(@"This is my float: %f \n\nAnd here again: %.2f", aFloat, aFloat);

In NSLog() you can use it like + (id)stringWithFormat:(NSString *)format, ...

float aFloat = 5.34245;
NSString *aString = [NSString stringWithFormat:@"This is my float: %f \n\nAnd here again: %.2f", aFloat, aFloat];

You can add other placeholders, too:

float aFloat = 5.34245;
int aInteger = 3;
NSString *aString = @"A string";
NSLog(@"This is my float: %f \n\nAnd here is my integer: %i \n\nAnd finally my string: %@", aFloat, aInteger, aString);
你曾走过我的故事 2024-10-27 23:35:38

从评论中移出

您确定执行带有 NSLog 的行吗?尝试在 main.m 中的自动释放池分配之后立即插入 NSLog

Moved from comment

Are you sure that line with NSLog is executed? Try to insert NSLog right after autorelease pool allocation in main.m

救赎№ 2024-10-27 23:35:38

真的很奇怪。只是为了实验:尝试将 NSLog 输出重定向到某个文件,如下所示:

freopen ("/out","w", stderr);
NSLog(@"1234567890");

如果有输出,则您的 stderr 出现问题。

Really weird. Just for the sake of experiment: try to redirect the NSLog output to some file like this:

freopen ("/out","w", stderr);
NSLog(@"1234567890");

If there is an output, then there is something wrong with your stderr.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文