• 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: how to test for NULL (or nil, or null)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: how to test for NULL (or nil, or null)
      • From: Pete Yandell <email@hidden>
References: 
 >Re: how to test for NULL (or nil, or null) (From: Pete Yandell <email@hidden>)

  • Prev by Date: Re: how to test for NULL (or nil, or null)
  • Next by Date: Re: how to test for NULL (or nil, or null)
  • Previous by thread: Re: how to test for NULL (or nil, or null)
  • Next by thread: Re: how to test for NULL (or nil, or null)
  • Index(es):
    • Date
    • Thread