Re: how to test for NULL (or nil, or null)
Re: how to test for NULL (or nil, or null)
- Subject: Re: how to test for NULL (or nil, or null)
- From: Denis Stanton <email@hidden>
- Date: Mon, 1 Mar 2004 11:38:16 +1300
Hi Pete
Thank you for the rapid help.
On Monday, March 1, 2004, at 11:16 AM, Pete Yandell wrote:
The short answer is that nil and NULL are both equivalent to zero, so
your first two tests are asking:
if (myNumber == 0)
(This is, of course, testing the pointer to myNumber against zero
rather than testing the value of myNumber.)
OK, that's clarified something I was missing.
[NSNull null] on the other hand is "a unique object used to represent
null values in collection objects (which dont allow nil values)",
hence the fact that it gets returned in place of nil by your
valueForKey: call.
If you want to avoid the compiler warning, do a bit of creative
casting:
if ((id)myNumber == (id)[NSNull null])
should work. You might even be able to get away with just casting one
of them to id...have a play around.
casting either one to (id) works, so my warning message is gone. Thank
you for your help.
Now that I look at it again, using == to compare two objects seems
wrong. Shouldn't it be isEqual: ? Or is that what the words "unique
object" are saying - [NSNull null] is a spacial case that == any other
NULL ?
Denis
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.