What is nil?

Discussion in 'iOS Programming' started by Red87445, Jul 27, 2011.

  1. Red87445 macrumors newbie

    Jul 1, 2011
    Objective-C is my first programming language, so I am not familiar with nils or nulls and such. In my book the code created "id action", and assigned it equal to nil. After that there was a switch case where action gets assigned a value. I was just wondering why action was set to nil? Is it just something you do with ids?

    Thank you!
  2. jiminaus macrumors 65816


    Dec 16, 2010
    An id variable is a pointer to an Objective-C object. nil is the value of an id variable that doesn't currently point to any Objective-C object. NULL is similar except NULL has the type void* not id, and is the value of any kind of pointer variable which doesn't current point to anything.

    I think almost always (if not always), nil == NULL == 0.
  3. Mr. Retrofire macrumors 603

    Mr. Retrofire

    Mar 2, 2010
  4. Sydde macrumors 68020


    Aug 17, 2009
    You have a poorly written book, designed to lead to later confusion. They should not be defining a variable named "action" of type "id", that is just plain wrong. "action" should really only be used as a property, of type "SEL", a sort of AppKit convention. Get a better book.
  5. Red87445 thread starter macrumors newbie

    Jul 1, 2011

    Um, thanks too.

    Well, this is a cocos2d book. The reason why I asked a question here and not on the cocos2d forum was because I thought I would get a faster reply, and this wasn't a cocos2d specific question.

Share This Page