• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSString -initWithData:encoding returning nil
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >NSString -initWithData:encoding returning nil (From: Alex Reynolds <email@hidden>)

  • Prev by Date: Re: NSString -initWithData:encoding returning nil
  • Next by Date: Re: capturing a partial screen.
  • Previous by thread: Re: NSString -initWithData:encoding returning nil
  • Next by thread: (no subject)
  • Index(es):
    • Date
    • Thread