3

Possible Duplicate:
is there a difference between (!object) and (object == nil)?

In iOS (Objective C) development, I've frequently seen (and used) the following short hand:

if (someObject)
{
    // do something
}

To check that someObject is not nil.

In other words, to mean the same as the following:

if (someObject != nil)
{
    // do something
}

Are these two if statements actually the same or is this not safe?

Community
  • 1
  • 1
JRG-Developer
  • 12,454
  • 8
  • 55
  • 81

1 Answers1

7

The two are exactly the same. They both are equally safe.

This feature is inherited from C, where comparing to zero is implicit.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523