small medium large xlarge

14 Mar 2009, 15:27
Geoffrey Porter (1 post)

I have a question about the initWithTitle method in Movie.m.

There’s an if statement @if (nil != self)@. Now shouldn’t that be @if (self != nil)@?

If not, please explain because this doesn’t make sense to me.



15 Mar 2009, 02:21
Bill Dudney (916 posts)

Hi Geoff,

Its an idiom used to avoid accidental assignment.

with something like this;


if(self == nil) {


There is a chance you could mistakenly type `

if(self = nil) {


Which would assign nil to self. Since nil is a constant it cannot be assigned and would generate a compiler error if you mistakenly typed.


if(nil = self) {


You must be logged in to comment