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: Brendan Younger <email@hidden>
- Date: Mon, 17 Jan 2005 09:34:39 -0600
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