Assigning to 'AppDelegate *' from incompatible type 'id<UIApplicationDelegate>'

ios, iphone, objective-c

Solution

since you know they equal, add a cast to let the compiler know

 AppDelegate* app = (AppDelegate*)[[UIApplication sharedApplication]delegate];

since this might come up in Swift too

 let app = UIApplication.shared.delegate as! AppDelegate

Problem

In my project it says Assigning to 'AppDelegate *' from incompatible type 'id'. What exactly is this? Why did this warning occur? I have declared in .m ``` AppDelegate *appdev; ``` and in viewDidLoad ``` { appdev = [[UIApplication sharedApplication]delegate]; <= warning here } ``` I want to hide this warning. What should I do? Thanks in advance.

Original source

Related problems