It seems to me that you do not want a global variable but, instead, an instance variable. In that case, your declaration:
@interface MainViewController : UIViewController <FlipsideViewControllerDelegate> {
NSMutableArray *sizedWordList;
}
in the header file is correct. However, in the implementation file, you cannot do the following outside of an instance method (or, if it were indeed a global variable, outside of a class method or a function):
sizedWordList = [[NSMutableArray alloc] init];
It is not legal in Objective-C. The correct place to initialise instance variables is the -init
method. Since your class is a subclass of UIViewController
, you should override its designated initialiser, -initWithNibName:bundle:
:
- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle {
self = [super initWithNibName:nibName bundle:nibBundle];
if (self) {
sizedWordList = [[NSMutableArray alloc] init];
}
return self;
}
Your -dealloc
method is almost correct — remember that you should always send [super dealloc]
at the end of your -dealloc
method:
- (void)dealloc
{
[sizedWordList release];
[super dealloc];
}
Having done that, you can use the array in any other instance method. For instance,
- (void)logWordList {
NSLog(@"%@", sizedWordList);
}