Outlet

An outlet is an instance variable that points to another object, enabling two objects in an application to communicate with each other at runtime. Outlets are useful in situations where your code needs to interact with nib-file objects. You declare an outlet in the header file of a class, and you make a connection between the outlet and another object using Interface Builder, Apple’s developmental application for creating user interfaces. The connection between the objects is stored in an Interface Builder archive called a nib file. When the application launches, the connection is restored.

image: Art/outlet.jpg

The object containing an outlet is usually a custom controller object such as an application delegate. The class of the object declares an outlet as an instance variable with the type qualifier of IBOutlet.

@interface AppDelegate : NSObject <UIApplicationDelegate> {
    IBOutlet UIWindow *window;
    IBOutlet UIPageControl *pageControl;
}
// method and property declarations here...

Xcode, the major developmental application, and Interface Builder are synchronized so that an outlet, once declared, is visible in Interface Builder.

You frequently define outlets so that you can send messages to view objects of the UIKit framework (on iOS) and the AppKit framework (on Mac OS X). These are often the same objects found in the Interface Builder library. Though an outlet, an object in your code can obtain a reference to an object defined in a nib file and then loaded from that nib file. You can make outlet connections between any objects that can be represented as instances in Interface Builder, even between two custom objects.

Prerequisite Articles

Sample Code Projects

Did this document help you? Yes It's good, but... Not helpful...


Last updated: 2010-07-07