Why isn't this code working? The app loads fine, however whenever I press the button the application locks up (doesn't crash) and returns me to Xcode and there is a red arrow pointing to one of the lines (Indicated on the line below).
I also get three warnings (not errors), one says 'NSMutableArray' may not respond to '-objectAt:' and the second one says unused variable 'soundToPlay' The third one say implicit declaration of function 'AudioServicesPlaySystemSound' Should I be concerned about those?
//In MainViewController.h
@interface MainViewController : UIViewController {
IBOutlet UIButton *Button;
}
@property (nonatomic, retain) UIButton *Button;
- (IBAction)playSound;
NSInteger currentSound;
NSMutableArray *soundArray;
@end
//In MainViewController.m
- (void)viewDidLoad {
currentSound = 0;
NSMutableArray *sounds = [[NSMutableArray alloc] init];
[sounds addObject: @"0.wav"];
[sounds addObject: @"1.wav"];
[sounds addObject: @"2.wav"];
[sounds addObject: @"3.wav"];
[sounds addObject: @"4.wav"];
[sounds addObject: @"5.wav"];
[sounds addObject: @"6.wav"];
[sounds addObject: @"7.wav"];
[sounds addObject: @"8.wav"];
[sounds addObject: @"9.wav"];
[sounds addObject: @"10.wav"];
[sounds addObject: @"11.wav"];
[sounds addObject: @"12.wav"];
[sounds addObject: @"13.wav"];
[super viewDidLoad];
}
- (IBAction)playSound {
NSString *soundToPlay = [soundArray objectAt: currentSound];
//First two errors here.
currentSound = (currentSound + 1) % [soundArray count]; //Red arrow points to this line.
AudioServicesPlaySystemSound (currentSound);
//Third error here.
}