Why Xcode shows warning when use AVAudioPlayer Delegate protocol in appdelegate.h file?
-
19-09-2019 - |
Question
//---------MyAppDelegate.h
@interface MyAppDelegate : NSObject <UIApplicationDelegate, AVAudioPlayerDelegate> {
//---in some other .m file, trying to acess the device token residing in MyAppDelegate ----------
MyAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
// Results in // warning: type 'id ' does not conform to the 'AVAudioPlayerDelegate' protocol
Solution
It is because of a type mismatch: - The UIApplication.delegate property returns an instance of type id - You are trying to cast this instance into MyAppDelegate which implements the UIApplicationDelegate and the AVAudioPlayerDelegate protocols. - As the type returned by the delegate property does not match the appDelegate type, you see the warning.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow