• 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: Method not seeing array as array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Method not seeing array as array


  • Subject: Re: Method not seeing array as array
  • From: "John C. Randolph" <email@hidden>
  • Date: Thu, 3 Feb 2005 19:12:10 -0800

On Feb 3, 2005, at 3:06 AM, Will Mason wrote:

'if(!self) return nil' line)
Is there something wrong with
if(!self) return nil;
other than its being a shorthand for
if(self == nil) return nil;
?
In reality no... it more clearly conveys your intent to test against
nil since nil explicitly implies no object.
The problem with "if (!self)" is that you're assuming that nil is equal
to zero. I have never seen documentation that says that nil has to be
zero. Although it's probably a safe assumption, it's still just an
assumption, as the documentation nowhere declares that nil has to be
zero. Therefore, I always use the construct "if (something == nil)"
rather than "if (!something)".

/usr/include/objc/objc.h. lines 51-57:

#ifndef Nil
#define Nil 0        /* id of Nil class */
#endif

#ifndef nil
#define nil 0        /* id of Nil instance */
#endif

As for documentation, according to the objective-C language overview

"The keyword nil is defined as a null object, an id with a value of 0. id, nil, and the other basic types of Objective-C are defined in the header file objc/objc.h."

So, the odds of Nil or nil becoming a non-zero value are pretty close to nil, in my opinion. There's an awful lot of code that would break if we changed it.

-jcr


John C. Randolph <email@hidden> (408) 974-8819 Sr. Cocoa Software Engineer, Apple Worldwide Developer Relations http://developer.apple.com/cocoa/index.html



_______________________________________________
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


References: 
 >Re: Method not seeing array as array (From: Will Mason <email@hidden>)

  • Prev by Date: Re: Loading a Dictionary
  • Next by Date: RE: Method not seeing array as array
  • Previous by thread: Re: Method not seeing array as array
  • Next by thread: Re: Method not seeing array as array
  • Index(es):
    • Date
    • Thread