[英]Why do we specify “weak” when testing in iOS?
I have noticed that the recommended way to test a view controller in XCode with Sencha testing is via instantiating it with 我注意到,使用Sencha测试在XCode中测试视图控制器的推荐方法是通过实例化它
@property (nonatomic, readwrite, weak) MyMainViewController* mainViewController;
Why not just 为什么不呢
@property (nonatomic, strong) MyMainViewController* mainViewController;
? ?
readwrite is not strictly necessary, as it is the default. readwrite并非严格必要,因为它是默认值。 As for strong vs weak, the main reason to use weak is to avoid a reference cycle (ie two objects that have strong references to each other so they will never be deallocated). 至于强弱对弱,使用弱的主要原因是避免引用循环(即两个对象具有强引用,因此它们永远不会被释放)。
As @borrrden mentioned, weak references are useful when try to avoid retain cycles. 正如@borrrden所提到的,当尝试避免保留周期时,弱引用很有用。
If you are looking into weak references, I would highly recommend reading this post by Mike Ash. 如果您正在研究弱引用,我强烈建议您阅读Mike Ash的这篇文章 。 It is important to understand the difference between zeroing weak references and non-zeroing weak references. 重要的是要理解归零弱引用和非归零弱引用之间的区别。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.