加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 17:17:58 所属栏目:百科 来源:网络整理
导读:我刚刚更新了我的 Xcode副本,发现我现在有很多警告.我正在努力让以下一个整理出来: ObAppDelegate *appdelegate = [[UIApplication sharedApplication]delegate]; 导致此警告: Initializing ObAppDelegate *__strong with an expression of incompatible t
我刚刚更新了我的 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];

这将消除警告.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读