This is usually done to prevent the use of an assignment operator instead of a comparison operator. If you accidentally typed this, for example:
if (object = nil)
It can compile, but thatβs not what you intended.
Using the second form, you provide a compile-time error if you make a mistake, since nil can not can be used as the left operand in an assignment.
Please note: I am not an objective C programmer, but this question is common to many languages.
source share