Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initialising ' ... *__strong' with an expression of incompatible type 'id<UIApplicationDelegate> _Nullable'

I have just updated my copy of Xcode and find that I now have lots of warnings. I am struggling to get the following one sorted out though:

ObAppDelegate *appdelegate = [[UIApplication sharedApplication]delegate];

causes this warning:

Initializing ObAppDelegate *__strong with an expression of incompatible type id<UIApplicationDelegate> _Nullable

Can anyone point me in the right direction to fix this warning? For information this is the related code used prior to the problem line:

- (NSManagedObjectContext *) managedObjectContext {
    return [(ObAppDelegate *) [[UIApplication sharedApplication] delegate] managedObjectContext];
}
like image 548
RGriffiths Avatar asked Dec 25 '16 21:12

RGriffiths


1 Answers

You have:

ObAppDelegate *appdelegate = [[UIApplication sharedApplication]delegate];

This will give a warning:

Initializing ObAppDelegate *__strong with an expression of incompatible type id<UIApplicationDelegate> _Nullable

Rewrite as:

ObAppDelegate *appdelegate = (ObAppDelegate*)[[UIApplication sharedApplication]delegate];

That will eliminate the warning.

like image 125
matt Avatar answered Oct 19 '22 08:10

matt