Here are the code I tried to convert NSData to NSString but the program return "Program received signal:SIGABRT".
NSString *string= [NSString stringWithUTF8String:[data bytes]];
OR
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
Is there any other better way to do it?
Swift-3
let string = data.base64EncodedString()
Here's a highly up-voted answer that shows how to do it. In a nutshell:
The first idea looks like a fail because of sending
[data bytes]
. stringWithUTF8String isn't prepared for a void *. The second idea looks as if it should work, even with nil input.Use this code
also see this tutorial..
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html
:)