• 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: 'nuther dumb question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 'nuther dumb question


  • Subject: Re: 'nuther dumb question
  • From: Quincey Morris <email@hidden>
  • Date: Fri, 16 May 2014 18:00:10 -0700

On May 16, 2014, at 16:46 , William Squires <email@hidden> wrote:

>  Why doesn't NSData have a +[NSData dataWithString:(NSString *)] or -[NSData initWithString:(NSString *)] method?

Because strings consist of *encoded* data, which (in principle) has no meaning outside the internals of the string itself**, and which is (in principle) architecture dependent***. Therefore strings (in principle) have no obvious external representation****.

> i.e. how do I convert the contents of an NSString object into an NSData object?

-[NSString dataUsingEncoding:allowLossyConversion:]

You can specify UTF-16 for the conversion, if you like.


** That is to say, we *know* that NSString objects are arrays of UTF-16 code points, and we use that knowledge, but you can’t interpret the string’s raw data without knowing the encoding.

*** That is, endianness is an issue.

**** And the most common one these days, I think, is UTF-8, which you can’t get from NSString without a conversion.

_______________________________________________

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: 
 >'nuther dumb question (From: William Squires <email@hidden>)

  • Prev by Date: 'nuther dumb question
  • Next by Date: Re: 'nuther dumb question
  • Previous by thread: 'nuther dumb question
  • Next by thread: Re: 'nuther dumb question
  • Index(es):
    • Date
    • Thread