在这个块中自我捕获可能导致保持循环 [英] capturing self strongly in this block is likely to lead to a retain cycle
本文介绍了在这个块中自我捕获可能导致保持循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在xcode中避免此警告。这里是代码片段:
How can I avoid this warning in xcode. Here is the code snippet:
[player(AVPlayer object) addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(0.1, 100)
queue:nil usingBlock:^(CMTime time) {
current+=1;
if(current==60)
{
min+=(current/60);
current = 0;
}
[timerDisp(UILabel) setText:[NSString stringWithFormat:@"%02d:%02d",min,current]];///warning occurs in this line
}];
推荐答案
self
这里是你的隐式属性访问 self.timerDisp
- 你不能引用 self
或属性 self
从 self
强烈保留的块内。
The capture of self
here is coming in with your implicit property access of self.timerDisp
- you can't refer to self
or properties on self
from within a block that will be strongly retained by self
.
你可以在访问 timerDisp
self > in your block:
You can get around this by creating a weak reference to self
before accessing timerDisp
inside your block:
__weak typeof(self) weakSelf = self;
[player addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(0.1, 100)
queue:nil
usingBlock:^(CMTime time) {
current+=1;
if(current==60)
{
min+=(current/60);
current = 0;
}
[weakSelf.timerDisp setText:[NSString stringWithFormat:@"%02d:%02d",min,current]];
}];
这篇关于在这个块中自我捕获可能导致保持循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文