Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 8 Does not display the whole NSLog output

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?

like image 758
Pointblaster Avatar asked Sep 09 '16 13:09

Pointblaster


1 Answers

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]);

or shorter:

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

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);

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]);

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

like image 96
Pointblaster Avatar answered Sep 21 '22 13:09

Pointblaster