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.

設置完畢,重新編譯運行。

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

推薦閱讀更多精彩內容