Cannot create __weak reference in file using manual reference counting

更新Xcode 9.3后編譯可能會出現這個錯:cannot create __weak reference in file using manual reference counting
解決方法:

1.可以設置build setting -> Apple LLVM9.1 - Language - Objective C -> Weak References in Manual Retain Release YES

image.png

2.用 __unsafe_unretained 代替 __weak,但是如果用 __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.

Answer from Apple:
This issue behaves as intended based on the following: We are in the process of implementing weak references in all Objective-C language modes. Since “__weak” has historically been ignored in non-ARC (and non-GC) language modes, we’ve added this error to point out places where the semantics will change in the future. Please update your bug report to let us know if this is still an issue for you.

原文鏈接:http://keepmovingxin.com/archives/36

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容