简体   繁体   English

为什么我们在iOS中测试时指定“弱”?

[英]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.

相关问题 为什么弱 NSString 属性没有在 iOS 中发布? - Why do weak NSString properties not get released in iOS? iOS:__ weak vs(弱) - iOS: __weak vs (weak) 在iOS中测试弱链接符号无法正常工作 - Testing for weak-linked symbol in iOS does not work as expected 为什么__weak属性需要运行时支持 - Why do __weak properties require runtime support 我们是否需要在Objective-C中使用弱自我? - Do we need to use weak self in blocks in Objective-C? 使用弱点有什么好处?什么时候可以使用弱点? - What is the benefits of using weak points or when can we use weak points? 为什么我们仍然在swift ios应用程序中使用NSDictionary和NSArrays? - Why do we still use NSDictionary and NSArrays in swift ios applications? 在 iOS 上使用 ARC 4,当使用 unsafe_unretained 而不是 weak 时,我是否需要 nil 我的 IBOutlet 属性? - Using ARC on iOS 4, do I need to nil my IBOutlet properties when using unsafe_unretained instead of weak? 当我们可以使用子类时,为什么我们需要类别? 当我们可以使用函数时,为什么我们需要块? - Why do we needed category when we can use a subclass? and Why we needed blocks when we can use functions? 如何弱链接 iOS 应用程序委托方法? - How do I weak link an iOS app delegate method?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM