Objective-C basics

Figure 2: Objective-C object structure
\begin{figure}\epsfbox{fig1.eps}\end{figure}

In Objective-C, objects are identified by a distinct data type id which is a pointer to the object. Every object carries an isa instance variable which points to the object's class — what kind of object it is. The objc_class structure stores the object's type description. Most objects are derived from the root class object called Object — it makes objects behave as Objective-C objects and enable them to cooperate with the run-time system. A message is sent to an object to get it to perform useful work (to apply a method). In Objective-C, message expressions are enclosed in square brackets (see Figure 3). The receiver is an object, and the message tells it what to do. In source code, the message is simply the name of a method and any arguments that are passed to it.

In Objective-C, messages are not bound to method implementations until run-time. The message function does everything necessary for dynamic binding. It first finds the procedure from the given message of particular receiver, then calls its procedure, passing it the receiving object and the arguments, and finally, returns a value.

Figure 3: Typical Objective-C message
\begin{figure}\begin{center}
{\em compiler converts to\\
function call}\\
$\un...
...w \mathtt{objc msgSend(receiver,selector,arg1,\ldots)}$\end{center}
\end{figure}