1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

In Init, does self refer to the class or the instance?

Discussion in 'Mac Programming' started by teguh123, Apr 7, 2011.

  1. macrumors member

    #1
    Also is there any case where we call alloc and not init after that?

    What confuses me is things like

    self= [super init]

    Basically, if self is a pointer to the class, we're tell self to point to the address described by [super init]

    The problem with that is self should already point to whatever address returned by alloc right?

    So why change it?
     
  2. macrumors 68030

    Catfish_Man

    #2
    In any instance method (-), self refers to the instance. In any class method (+), self refers to the class. Always call an init method after calling +alloc. The reason to set it is that some classes play tricks in -init and don't return the same object that +alloc did.
     
  3. macrumors 603

    #3
    Cocoa Fundamentals Guide

    In particular, read the sub-section on "Basic Subclass Design". Ideally, you should read the entire guide.
     

Share This Page