ios - Xcode 8 不显示整个 NSLog 输出

标签 ios objective-c xcode nslog

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

我正在打印数组和字典,如果这有什么不同的话。

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

有没有其他人注意到这一点?有人知道如何解决这个问题吗?

最佳答案

正如@Lion 在他的评论中所述,最简单的方法是改用 printf。它的工作方式与 NSLog 不完全相同,但它显示了您想要的内容。

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

或更短:

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

一个技巧是在 printf 格式的开头或结尾放置一个“\n”,这样它将分隔输出而不是将所有内容放在一行中。像这样:

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

如果你不喜欢每次都写 printf,你可以使用 #define 将代码重定向到 printf,就像这样(代码来自 @xfdai):

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

希望这只是 Apple 的一个错误,很快就会得到修复,在那之前我们可以使用它。

关于ios - Xcode 8 不显示整个 NSLog 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39412917/

相关文章:

ios - 在 Xcode 7.2 iOS 模拟器上添加 Apple Pay Card

ios - <错误>:CGImageCreateWithImageProvider:无效的图像大小:150 x150。__connection_block_invoke_2中的错误:连接中断

iOS - [WKWebView .cxx_construct] 只能在主线程中使用

IOS:OpenGL + UIScrollView + UILabel:iPad 3 与 2 上的性能不佳

objective-c - 以编程方式打开位置服务 View

iphone - setBackgroundImage :Forstate and setImage:Forstate: 有什么区别

ios - 通过函数 Swift 传递一个类 (UILabel) 及其属性

ios - 由于信号 : Killed: 9,Xcode 8 (Swift 3) 命令失败

ios - 自从 Lottie 3.0 更新以来,setAnimation 发生了变化吗?

ios - 重新排列数组中的字母并检查排列是否在数组中