Re: == nil vs. isEqual:nil
Re: == nil vs. isEqual:nil
- Subject: Re: == nil vs. isEqual:nil
- From: Jim Correia <email@hidden>
- Date: Thu, 16 Aug 2001 14:49:38 -0400
At 12:49 PM -0500 8/16/01, Jonathan Hendry wrote:
It's a little better if you can get into the habit of doing
if (nil == anObject)
I agree that this is an excellent habit to get into (and it can be
hard because as you say the code to yourself as you are writing it,
it sometimes just sounds wrong).
That way, if you accidentally do "if (nil = anObject)" you'll
get a compiler warning.
On the other hand, if you accidentally type "if (anObject = nil)" then
you get no compiler warning and anObject gets set to nil.
Most compilers have a warning for possible unintended assignments.
In gcc, it is -Wparentheses. Worth turning on, even if you write
code like the first example but sometimes inherit other people's code.
Jim