Πέμπτη, 15 Μαρτίου 2012

isa - super - self

short notes:

isa
  • NSObject has many methods, but only one  instance variable: the isa pointer. 
  • Every object's isa pointer points back to the class that created it. 
  • We call it the isa pointer because an object "is a " instance of that class.  At runtime when a message is sent to an object, that object goes to the class named in its isa pointer and says, "I was sent this message. Run the code for the matching method". This is different than most compiled languages, where the method to be executed is determined at compile time. 
  • The isa pointer, as the name suggests, points to the object's class which maintains a dispatch table. This dispatch table essentially contains pointers to the methods the class implements, among other data. 
  • The value of the isa pointer does not necessarily reflect the actual class of the instance. When an observer is registered for an attribute of an object the isa pointer of the observed object is modified, pointing to an intermediate class rather than at the true class. 
  • You should never rely on the isa pointer to determine class membership. Instead, you should use the class method to determine the class of an object instance. 

A little confused from the above i will get back on this ..!?!?!?

super:

  • To be precise, the super directive says "Run this method, but start the search for its implementation at my superclass".
  • Each version of init follows this procedure, so classed initialize theri instance variables in the order of inheritance

- (id) init
{
  self = [super init];
  if (self) {
  ...
  }
}

  • super is simply a flag to the compiler telling it where to begin searching for the method to perform; it's used only as the receiver of a message. But self is a variable name that can  be used in any number of ways, even assigned a new value (see Redefining self)
  • super is a flag that tells the compiler to search for the method implementation, begins in the superclass of the class that defines the method where super appears. 
  • wherever super receives a message, the compiler substitutes another messaging routine for the objc_msgSend function. 



self:

  • is one of the hidden parameters that the messaging routine passes to every method; it's a local variable that can be used freely within a method implementation, just as the names of instance variables
  • self searches for the method implementation in the usual manner, starting in the dispatch table of the receiving object's class. 



from Big Ned Ranch Guide Object C & ios Programming + Documentation

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου