Re: NSString -initWithData:encoding returning nil
Re: NSString -initWithData:encoding returning nil
- Subject: Re: NSString -initWithData:encoding returning nil
- From: Jens Alfke <email@hidden>
- Date: Fri, 4 Sep 2009 14:35:30 -0700
On Sep 4, 2009, at 2:28 PM, Alex Reynolds wrote:
NSString *encryptedString =
[[[NSString alloc] initWithData:encryptedStringData
encoding:NSUTF8StringEncoding] autorelease];
You can't interpret arbitrary binary data as a UTF-8 string. The UTF-8
encoding has certain rules — it's a compressed packing of Unicode —
and there are a lot of byte sequences that aren't valid UTF-8.
Attempting to create an NSString from such data will fail with a nil
result.
If you want binary data, stick with NSData. If you want to represent
that data in a textual way, you'll have to translate it to something
like hex or base64.
—Jens_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden