What is nil?

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

  1. macrumors newbie

    Joined:
    Jul 1, 2011
    #1
    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. macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    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. macrumors 601

    Mr. Retrofire

    Joined:
    Mar 2, 2010
    Location:
    www.emiliana.cl
    #3
  4. macrumors 68000

    Sydde

    Joined:
    Aug 17, 2009
    #4
    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. thread starter macrumors newbie

    Joined:
    Jul 1, 2011
    #5
    thanks!

    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