- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 xcode 中打开了一个新标志,并收到警告“弱接收器在 ARC 模式下可能不可预测地为空”。这让我很困惑,因为它当然可能为零。
最佳答案
我一周前问过这个问题,但没有收到任何答复,但格雷格·帕克在邮件列表上回答了它。所以我重新发布答案。
We added this warning because we saw lots of subtle and hard to debug problems in practice.
The recommended practice is to read the weak variable into a strong local variable once, and then use the local variable.
- Greg Parker
在我第一次回答这个问题时,我发布了类似的内容,我认为测试 nil 应该已经足够了
if (self.rootViewController) {
[self.rootViewController controllerWillChangeContent:controller];
}
问题是 self.rootViewController 可能在检查 nil 和完成调用的方法之间的空间中变为 nil。我们被告知要做的是分配一个强大的本地引用并像这样使用它
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
RootViewController *rootVC = self.rootViewController;
if (rootVC) {
[rootVC controllerWillChangeContent:controller];
}
}
斯蒂芬·巴特勒 (Stephen Butler) 简洁地重申了此警告旨在解决的问题
What we're trying to prevent is the object instance getting deallocedwhile you're in [someMethod] because you called it off a weakreference and nothing is holding onto the object strongly.
关于cocoa-touch - 如何正确寻址 "Weak receiver may be unpredictably null in ARC mode",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11899134/
我是一名优秀的程序员,十分优秀!