Help for Objective C Starter - Self and Super

Discussion in 'Mac Programming' started by Flamehearted, Aug 17, 2010.

  1. Flamehearted macrumors newbie

    Aug 4, 2010
    Hi all,

    Would anyone be able to give me an idiot proof description of Self and Super in objective C - I am struggling to understand these two from what I have read so far.

    Thanks in advance,

  2. robbieduncan Moderator emeritus


    Jul 24, 2002
    self refers to the "current" instance of the class in question. It is a pointer back to the object. super refers to the instance of the superclass (the class this class inherits from). Note that these two instances are actually one object but the super pointer allows us to execute overridden methods.
  3. mrbash macrumors 6502

    Aug 10, 2008
    super is an aspect of Polymorphism in OO speak.

    If Object B is derived from Object A, calling super from an instance of Object B would get you the same instance but all of your methods and attributes would be from Object A. So if Object B overrides any methods from Object A, calling "super" would allow you to get the behavior from Object A.
  4. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    There is a description in this article, at the heading "Messages to self and super":

    • self searches for the method implementation in the usual manner, starting in the dispatch table of the receiving object’s class. In the example above, it would begin with the class of the object receiving the reposition message.
    • super starts the search for the method implementation in a very different place. It begins in the superclass of the class that defines the method where super appears. In the example above, it would begin with the superclass of the class where reposition is defined.
    You should read the complete original description, including its examples, then ask specific questions if something doesn't make sense.

Share This Page