What describes an "Outlet" best in objective-c / Cocoa?

I just think of it as a pointer to a UI control. Once I made that mental connection in my mind, it made sense.


I would say they are the bridge that connects your user interface objects to the code that uses them. Like the name suggests, they provide a spot to "plug in" your UI to your code.


From a code point-of-view and IBOutlet is only a hint for Interface Builder. It's actually a macro that compiles to, well, nothing at all. That is, the compiler completely removes when compiling.

But Interface Builder can scan your code for IBOutlet so when you right-click on an object in IB you can see all the outlets that you could connect to other objects.

alt text http://img27.imageshack.us/img27/5512/picture820090228.png

In this example, delegate is a member variable of UIApplication and it is an IBOutlet too.


It's an instance variable that shows up in Interface Builder, so that you can use IB to plug another object into the outlet.

When you load the nib, the nib-loading system will do the requisite magic to make sure the right object shows up in each outlet.

Edit: I'd intended to write a full blog post around this image (I changed my mind after finishing the image), but even alone, it should help clarify outlets for people. Here you go:

The outlet relationship.
(source: boredzo.org)