Re: Definition of Nil and nil was: NSData testing for NULL [SOLVED]
Re: Definition of Nil and nil was: NSData testing for NULL [SOLVED]
- Subject: Re: Definition of Nil and nil was: NSData testing for NULL [SOLVED]
- From: Robin Hermann <email@hidden>
- Date: Mon, 17 Jan 2005 16:46:48 +0100
Brendan,
Thanks,
I've read the statement about the CString (soon deprecated, should be using UTF8String, according to the Apple docs)
As an excuse: I copied the code sample from the Apple documentation...something needs an update, I guess ;-)
I will look into [NSString initWithData:encoding:] to see what it can do for me, it sounds very logic to use that...
Robin Hermann
On 17 jan 2005, at 16:34, Brendan Younger wrote:
On Jan 17, 2005, at 8:54 AM, Robin Hermann wrote:
Mark,
Thank you for making this as clear as possible.
Now using:
NSData *note = [record objectForKey:@"notes"];
if (note != Nil && [note isKindOfClass:[NSData class]]) {
unsigned long len = [note length];
unsigned char noteBuffer[len];
[note getBytes:noteBuffer];
NSString *noteString = [NSString stringWithCString:noteBuffer length:len];
[notes setString:noteString];
}
and working perfect ;-)
I'm sure it does work okay, but that's really not at all what you want to be doing. Apple has said repeatedly that the "C string" methods are going to be deprecated very soon because they depend on the current locale settings. Besides, what you're doing there is needlessly wasteful. There's no reason to allocate "noteBuffer" when you have -[NSString initWithData:encoding:] at your disposal, especially since you can then specify the encoding as well.
Brendan Younger
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden