To add a property to a UIViewController, you first need to declare it in the UIViewController’s header file.

Here’s an example:

//
//  RootViewController.h
//  App Name
//
//  Created by Miscellanea on 11/03/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController
{
    NSMutableArray *items;
    int index;
}

@property (nonatomic, retain) NSMutableArray *items;
@property (nonatomic) int index;

@end


Note that primitives (like int and float) don’t need the retain attribute in the @property statement.

Once a property has been declared in the header file, it can be defined in the corresponding implementation (.m) file:

//
//  RootViewController.m
//  App Name
//
//  Created by Miscellanea on 11/03/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "RootViewController.h"

@implementation RootViewController

@synthesize items, index;

– (void)dealloc
{
    [super dealloc];

    [self.items release];
}

– (void)viewDidUnload
{
    [super viewDidUnload];

    self.items = nil;
}

@end


You first need to synthesize the property at the top of the file. If you declared the property with the retain attribute in the header, it will also need to be released in the dealloc method, and generally set to nil in the viewDidUnload method as well.

Primitive properties (like int and float) only need to be synthesized.