Problem with playing a sound when a button is clicked

in my code:

#import "MyViewController.h"
#import "AVFoundation/AVAudioPlayer.h"

- (IBAction)playSound{
    AVAudioPlayer *myExampleSound;

    NSString *myExamplePath = [[NSBundle mainBundle] pathForResource:@"myaudiofile" ofType:@"caf"];

    myExampleSound =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:myExamplePath] error:NULL];

    myExampleSound.delegate = self;

    [myExampleSound play];


But it is showing a warning that Class MyViewController does not implement AVAudioplayerDelegate.

Anyone please help. I had included the AVFoundation.Framework.


That warning should not affect the actual function of the code.

If you want to suppress the warning, in the header of your view controller do this:

@interface MyViewController : UIViewController <AVAudioPlayerDelegate> {

This lets the compiler know that your class does respond to the AVAudioPlayerDelegate (even though all the methods in that protocol are optional). See here.

Need Your Help

Select text from TextView?


Is it possible to select text from a TextView(including highlight) ?

How to find multiple values in array?

c# arrays

My code below looks only for one letter, how can I look for combination of letters? For ex.: to find letters "ac" in my array and to output them to textBox2