Challenge 2 and IBOutlet Question


Hi There,

I have a working challenge 2 but I kinda stopped reading at the bottom of page 142 and ignored the provided code. I just relied on what we had done previously. What I am interesting in finding out is why the IBOutlet is defined inside the interface on page 143 (RMDocument.h) rather than using the method using the Assistant Editor as shown in the previous chapters?

The code from the book looks like this:

#import <Cocoa/Cocoa.h>

@interface RMDocument : NSDocument <NSTableViewDataSource> {
	NSMutableArray *employees;
	IBOutlet NSTableView *tableView;
- (IBAction)createEmployee:(id)sender;
- (IBAction)deleteSelectedEmployee:(id)sender;

My code looks like this:

#import <Cocoa/Cocoa.h>

@interface RMDocument : NSDocument <NSTableViewDataSource>
    //declare array
    NSMutableArray *employees;

@property (weak) IBOutlet NSTableView *tableView;

//button actions

I’m sure I have missed something obvious! Thanks for any explanation.

Kind Regards,



Hi Adam,

I think your question is similar to this one here.




Using IBOutlet on the instance variable is a somewhat older style. Now that we have properties we often use IBOutlet on the property instead. They are equivalent as far as creating an outlet that the Interface Builder editor will recognize. (Of course, creating a full blown @property implies a setter and a getter method in addition to the instance variable.) In most cases it doesn’t make much sense for outlets to be exposed publically as properties, which is why some people prefer the instance variable IBOutlet style. The assistant editor likes to create properties, as you’ve found.