最近兩天升級了一下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.
設置完畢,重新編譯運行。