Re: Newbie: Encoding NSData to a string
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