Xcode 8不显示整个NSLog输出 [英] Xcode 8 Does not display the whole NSLog output

查看:477
本文介绍了Xcode 8不显示整个NSLog输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天升级到Xcode 8 GM后,我注意到NSLog没有将整个日志消息打印到控制台。当针对下载大量信息的API工作时尤其明显,例如REST API从数据库下载所有产品,它只显示第一个产品的前30个键,其余信息被剪切...

After upgrading to Xcode 8 GM today i noticed that NSLog isn't printing the whole log-message to the console. This is especially noticeable when working against an API that downloads a lot of information, like a REST API download all the products from a database, it only shows the first 30 keys on the first product, the rest of the information is clipped...

我正在打印数组和字典,如果这有任何区别。

I'm printing arrays and dictionaries, if that makes any difference.

NSDictionary *allProducts = responseFromAPI;
NSLog(@"All products:%@", allProducts);

有没有人注意到这个?有没有人知道如何解决这个问题?

Have anyone else noticed this? And does anybody know how to fix this?

推荐答案

正如@Lion在评论中所描述的那样,最简单的方法是使用printf代替。它不像NSLog那样工作,但它显示了你想要的东西。

As @Lion described in his comment the easiest possible way is to use printf instead. It does not work exactly like NSLog but it shows what you want.

NSDictionary *allProducts = responseFromAPI;
NSString * string = [NSString stringWithFormat: @"%@", allProducts];
printf("%s", [string UTF8String]);

或更短:

NSDictionary *allProducts = responseFromAPI;
printf("%s", [NSString stringWithFormat: @"%@", allProducts].UTF8String);

提示是在printf格式的开头或结尾放置一个\ n,以便它会将输出分开而不是全部放在一行中。这样的事情:

A tip is to place a "\n" at the beginning or end of the printf format so it will separate the outputs and not put all in a single line. Something like this:

printf("%s\n", string.UTF8String);

如果您不喜欢每次使用#define重定向代码而不想编写printf到这样的printf(来自@xfdai的代码):

If you don't like writing printf instead every time you can use a #define to redirect the code to an printf like this (code from @xfdai):

#define NSLog(FORMAT, ...) printf("%s\n", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);

希望这只是Apple的一个错误,很快就会修复,直到那时我们才能使用它。

Hopefully this is just a bug from Apple that will get fixed soon, until then we can use this.

这篇关于Xcode 8不显示整个NSLog输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆