我刚开始学习iOS开发。我在我的代码中使用了一些NSLog
语句,但它们似乎没有在任何地方输出。我的应用程序正在使用调试配置,我正在Xcode中的iPhone模拟器中运行我的应用程序。我已经检查了Xcode控制台(在“运行”菜单下)和Mac上的Console.app,但没有任何内容。
可能是什么问题?
答案 0 :(得分:16)
确保已激活Console
。为此,您可以:
答案 1 :(得分:6)
NSLog()
输出确实显示在Console Mac OS X应用程序中。
转到All Messages
,然后根据您的应用名称进行过滤以消除绒毛,然后再次运行。如果在执行程序期间实际遇到NSLog代码,您将在输出中看到它。
答案 2 :(得分:5)
像这样使用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);
答案 3 :(得分:2)
从评论中移出
您确定执行了NSLog
行吗?尝试在main.m
NSLog
答案 4 :(得分:1)
真的很奇怪。仅仅为了实验:尝试将NSLog输出重定向到某个文件,如下所示:
freopen ("/out","w", stderr);
NSLog(@"1234567890");
如果有输出,那么您的stderr
会出现问题。