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

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

概述我刚刚更新了我的 Xcode副本,发现我现在有很多警告.我正在努力让以下一个整理出来: ObAppDelegate *appdelegate = [[UIApplication sharedApplication]delegate]; 导致此警告: Initializing ObAppDelegate *__strong with an expression of incompatible typ 我刚刚更新了我的 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];

这将消除警告.

总结

以上是内存溢出为你收集整理的objective-c – 使用不兼容类型’id _Nullable’的表达式初始化’… * __ strong’全部内容,希望文章能够帮你解决objective-c – 使用不兼容类型’id _Nullable’的表达式初始化’… * __ strong’所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1003402.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存