Reputation: 2689
What exactly is the difference between
if(!variable)
do something
and
if(variable != nil)
do something
Upvotes: 0
Views: 207
Reputation: 3334
They're the exactly the same:
if ( !var )
is equivalent to
if ( var != nil )
Upvotes: 1
Reputation: 75058
As noted you have the logic a bit backwards, but outside of that they would work the same.
The main thing to consider is that ( variable != nil )
is a bit more clear as to what you are checking and what type the variable is, since someone may start thinking the variable is a boolean.
Upvotes: 4