Are you asking how to call playFailSound: ? Or are you asking how to declare the sounds array in your header file to make it an instance variable?
The first problem you have is that you're using a different variable name for the array in the two methods. in viewDidLoad you're using soundArray, and in playFailSound you're using sounds.
In your header file, you'll need to declare an array as an instance variable:
#import <UIKit/UIKit.h>
@interface MyObject : NSObject {
NSArray *_sounds; //declare the variables
NSInteger _currentSound; //this doesn't need to be unsigned, does it?
}
@property(nonatomic, retain) NSArray *sounds; //property
@property(value) NSInteger currentSound; //property
//method declarations
- (void) playFailSound;
- (void) playSoundWithFilename:(NSString *)fileName;
@end
You'll notice I used an underscore in the name of the variable, but didn't in the property. This way you won't accidently use the variable when you mean to use the property.
In your implementation file you'll need the following:
#import "MyObject.h"
@implementation MyObject
//synthesize the getters and setters, tell it what iVar to use
@synthesize sounds=_sounds, currentSound=_currentSound;
- (void)viewDidLoad {
NSArray *tempSounds = [[NSArray alloc] initWithObjects: @"0.wav",
@"1.wav",
@"2.wav, nil];
self.currentSound = 0; //use the setter
self.sounds = tempSounds; //use the setter
[tempSounds release]; //we don't need this anymore, get rid of the memory leak
[super viewDidLoad];
}
- (void) playFailSound {
self.currentSound=self.currentSound++; //use the getters and setters
if (self.currentSound >= [self.sounds count]) {
self.currentSound = 0;
}
[self playSoundWithFilename:[self.sounds objectAtIndex:self.currentSound]];
}
- (void) playSoundWithFilename:(NSString *)filename {
//you fill this in
}
@end
Now all you need to do is call playFailSound from somewhere, and fill in the part that actually plays the sound.
Essentially, for a two methods to refer to the same variable that isn't passed between them, it needs to be a instance variable.
This is pretty basic stuff, so if you don't get what I'm explaining here, I'd suggest re-reading some of Apple's introductory materials.