objective-c – 使用不兼容类型’id _Nullable’的表达式初始化’… * __ strong’

前端之家收集整理的这篇文章主要介绍了objective-c – 使用不兼容类型’id _Nullable’的表达式初始化’… * __ strong’前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我刚刚更新了我的 Xcode副本,发现我现在有很多警告.我正在努力让以下一个整理出来:

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

导致此警告:

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

有人能指出我正确的方向来修复这个警告吗?有关信息,这是问题行之前使用的相关代码

- (NSManagedObjectContext *) managedObjectContext {
    return [(ObAppDelegate *) [[UIApplication sharedApplication] delegate] managedObjectContext];
}

解决方法

你有:

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

这会发出警告:

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

重写为:

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

这将消除警告.

猜你在找的Xcode相关文章