views:

23

answers:

1

In something like this:

@interface Control_FunViewController : UIViewController {
    UITextField *nameField;
    UITextField *numberField;
}
@property (nonatomic, retain) IBOutlet UITextField *nameField;
@property (nonatomic, retain) IBOutlet UITextField *numberField;

I understand that "UITextField *nameField;" is an instance variable and "@property ..." is a property. But what do these individual things do?

I guess what I'm really asking is how the property is used for example in the implementation file (.m)

+1  A: 

The instance variables are the actual variables, whereas the properties are the equivalent of

- (UITextField *)nameField;
- (void)setNameField:(UITextField *)newTextField;

and completely optional. They are also used by the compiler to understand exactly what you want when you @synthesize a variable. Basically the properties and corresponding @synthesize (or custom implementation) allow OTHER classes access to variables, and are completely optional. It is in fact generally recommended, as per standard object oriented encapsulation principals, not to use properties unless you specifically intend for them to be used by external classes. However, you still need Interface Builder to recognize the UITextFields (presumably) which is why we typically put the IBOutlet decorator before the ivar declaration, not the property.

Jared P