warning: class Xxx does not implement the 'AVAudioPlayerDelegate' protocol
オーディオを再生させたりするAVAudioPlayerクラスを使おうとした時に発生した警告
AVAudioPlayerクラスのインスタンスを生成しているところで警告が出た。
ClockAppDelegate.m
@implementation ClockAppDelegate - (void) playAnnounce: (NSTimer *) timer { // AVAudioPlayerのインスタンス生成 AVAudioPlayer* avap = [ [AVAudioPlayer alloc] initWithContentsOfURL: url error: nil ]; } @end
■警告の内容
warning: class 'ClockAppDelegate' does not implement the 'AVAudioPlayerDelegate' protocol
警告: ClockAppDelegateクラスはAVAudioPlayerDelegateプロトコルを実装していない
ヘッダファイルのクラスの宣言をしているところで、AVAudioPlayerDelegateというプロトコルを書き忘れているようだ。
ヘッダファイルの構成は以下のようになっている。
@interface クラス名: スーパークラス名<プロトコル, プロトコル, ・・・> { インスタンス変数の宣言 } メソッドプロトタイプ宣言 @end
■対応
AVAudioPlayerDelegateプロトコルを追加した。
ClockAppDelegate.h
@interface ClockAppDelegate : NSObject <UIApplicationDelegate, AVAudioPlayerDelegate> { IBOutlet UIWindow* window; } @property (nonatomic, retain) IBOutlet UIWindow *window; @end