为什么Xcode在appdelegate.h文件中使用AVAudioPlayer委托协议时会显示警告?

时间:2009-11-13 10:27:23

标签: xcode avaudioplayer uiapplicationdelegate

// --------- MyAppDelegate.h

@interface MyAppDelegate : NSObject <UIApplicationDelegate, AVAudioPlayerDelegate> {

// ---在其他一些.m文件中,尝试访问驻留在MyAppDelegate中的设备令牌----------

MyAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];

//结果 //警告:类型'id'不符合'AVAudioPlayerDelegate'协议

1 个答案:

答案 0 :(得分:1)

这是因为类型不匹配: - UIApplication.delegate属性返回类型为id的实例 - 您正在尝试将此实例强制转换为实现UIApplicationDelegate和AVAudioPlayerDelegate协议的MyAppDelegate。 - 由于delegate属性返回的类型与appDelegate类型不匹配,您会看到警告。