You must specify NSString using an encoding that NSData bytes can be interpreted as a valid string. However, it will not change / convert your string between encodings. If the NSData object contains a sequence of bytes that is not valid in UTF-8, it will simply return zero.
user529758
source share