Code Created When Using ctrl + Drag to Connect UI Elements in Xcode 4

I was curious what code is generated in Xcode 4 when you ctrl + drag from a UI element to the header of the xib’s view controller.

For outlets, Xcode will create the @property in the header file and add a @synthesize to the implementation file. It will also add an entry to the viewDidUnload method to set the value of the outlet to nil. If your implementation file does not have a viewDidUnload method one will be created. Here is the code made for a label outlet:

-ViewController.h-

@property (weak, nonatomic) IBOutlet UILabel *label;

-ViewController.m-

@synthesize label;

in the viewDidUnload method

[self setLabel:nil];
For actions, Xcode creates an entry in the header and an empty method in the implementation file. Here is the code generated for an action:

-ViewController.h-

– (IBAction)buttonPressed:(id)sender;

-ViewController.m-

– (IBAction)buttonPressed:(id)sender {

}