Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 713
Gajendra K Chauhan Avatar asked Jul 10 '13 05:07

Gajendra K Chauhan


Video Answer


1 Answers

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 
like image 63
Daij-Djan Avatar answered Sep 29 '22 05:09

Daij-Djan