Xcode 7.3 使用__weak __typeof(self) weak self = self 出现的错误

最近两天升级了一下Xcode 7.3 出现
__weak typeof(self) weakSelf = self; 无法使用的错误

报错位置:

 __weak  typeof(self) weakSelf = self;

错误提示:

Cannot create __weak reference in file using manual reference counting
// 不能在文件中使用手动引用创建 __weak  引用,工程一般是自动管理的,不是在非ARC模式

解决方案一

在build setting 直接在search 内搜索 关键字 weak 就找到了

选中项目名字-> Target->Build Setting -> Apple LLVM7.1 - 
Language - Objective C ->Weak References in Manual Retain Release   将其value 设置为YES,

解决方案二:

将  `__weak`  替换成 `__unsafe_unretained`  
使用 `__unsafe_unretained ` 请注意以下问题:

注意事项 使用 __unsafe_unretained 注意以下问题:

__unsafe_unretained specifies a reference that does not keep the 
referenced object alive and is not set to nil when there are no 
strong references to the object. If the object it references is 
deallocated, the pointer is left dangling.

设置完毕,重新编译运行。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容