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,114
  • 8
  • 55
  • 80

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
  • 697,062
  • 78
  • 1,055
  • 1,465