xcode 使用不兼容类型 'id<UIApplicationDelegate> _Nullable' 的表达式初始化 ' ... *__strong'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41324811/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Initialising ' ... *__strong' with an expression of incompatible type 'id<UIApplicationDelegate> _Nullable'
提问by RGriffiths
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:
我刚刚更新了我的 Xcode 副本,发现我现在有很多警告。不过,我正在努力解决以下问题:
ObAppDelegate *appdelegate = [[UIApplication sharedApplication]delegate];
causes this warning:
导致此警告:
Initializing
ObAppDelegate *__strong
with an expression of incompatible typeid<UIApplicationDelegate> _Nullable
ObAppDelegate *__strong
用不兼容类型的表达式初始化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];
}
回答by matt
You have:
你有:
ObAppDelegate *appdelegate = [[UIApplication sharedApplication]delegate];
This will give a warning:
这将发出警告:
Initializing
ObAppDelegate *__strong
with an expression of incompatible typeid<UIApplicationDelegate> _Nullable
ObAppDelegate *__strong
用不兼容类型的表达式初始化id<UIApplicationDelegate> _Nullable
Rewrite as:
改写为:
ObAppDelegate *appdelegate = (ObAppDelegate*)[[UIApplication sharedApplication]delegate];
That will eliminate the warning.
这将消除警告。