Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Can someone explain in an humanly understandable way what an "Outlet" is?

like image 665
Thanks Avatar asked Feb 27 '09 20:02

Thanks


People also ask

What is an outlet in programming?

An outlet is a property of an object that references another object. The reference is archived through Interface Builder. The connections between the containing object and its outlets are reestablished every time the containing object is unarchived from its nib file.

What is IBAction Objective C?

IBAction and IBOutlets are used to hook up your interface made in Interface Builder with your controller. If you wouldn't use Interface Builder and build your interface completely in code, you could make a program without using them.


2 Answers

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)

like image 123
Peter Hosey Avatar answered Nov 09 '22 13:11

Peter Hosey


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.

like image 34
elasticrat Avatar answered Nov 09 '22 14:11

elasticrat