• 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: Newbie: Encoding NSData to a string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie: Encoding NSData to a string


  • Subject: Re: Newbie: Encoding NSData to a string
  • From: Andreas Mayer <email@hidden>
  • Date: Mon, 26 Mar 2007 07:31:03 +0200


Am 26.03.2007 um 07:05 Uhr schrieb Joao Lourenco:

dataEncodedPicture = [imageRep representationUsingType:NSJPEGFileType properties:imageProps];
NSString* stringEncodedPicture = [[NSString alloc] initWithData: dataEncodedPicture encoding: NSUTF8StringEncoding];

NSString's -initWithData:encoding: does not do what you seem to think it does.


Not every sequence of bytes is a valid representation of an utf8 string. So you can't just convert any arbitrary block of data into such a string.

Encode the image as an "ascii" string

Well, in that case you need to convert that data stream to a stream of ASCII characters first. Note that ASCII is only a small subset of the unicode character set. I suggest you use one of the common encodings for that purpose, like BASE64 or UUENCODE.


Also, unless you omitted some -release messages, you are leaking objects in the code you posted. Read up on Cocoa memory management.


Andreas _______________________________________________

Cocoa-dev mailing list (email@hidden)

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: 
 >Newbie: Encoding NSData to a string (From: Joao Lourenco <email@hidden>)

  • Prev by Date: Newbie: Encoding NSData to a string
  • Next by Date: Re: Newbie: Encoding NSData to a string
  • Previous by thread: Newbie: Encoding NSData to a string
  • Next by thread: Re: Newbie: Encoding NSData to a string
  • Index(es):
    • Date
    • Thread