Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS10 NSLog is limited to 1024 chars strings

In iOS10 the NSlog are limited to 1024 characters has anybody know a workaround to print complete string.

like image 490
Naveen Shan Avatar asked Sep 16 '16 18:09

Naveen Shan


3 Answers

try printf then instead of NSLog like,

   printf("%s", [string UTF8String]);

It may works

like image 52
Ketan Parmar Avatar answered Nov 12 '22 09:11

Ketan Parmar


I thinks this is a same question with [ NSLog on devices in iOS 10 / Xcode 8 seems to truncate? Why?, I will also post my answer here, in case you want to use printf instead.

This is a temporary solution,since I think it's a bug.

Just redefine all NSLOG to printf in a global header file.

#define NSLog(FORMAT, ...) printf("%s\n", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
like image 24
xfdai Avatar answered Nov 12 '22 08:11

xfdai


a Swift workaround for this new Xcode8 and Sierra “feature”…

func Log(_ format:String, _ args:CVarArg...) {
    let output = withVaList(args, { (p) -> NSString in
        NSString(format: format, arguments: p)
    }) as String
    print( output )
}

Of course, this won’t have the features of NSLog that we may require such as the time stamp, bundle name, and thread stuff (including serialization).

like image 36
AutomatonTec Avatar answered Nov 12 '22 08:11

AutomatonTec