简体   繁体   中英

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

@property (nonatomic, readwrite, weak) MyMainViewController* mainViewController; 

Why not just

@property (nonatomic, strong) MyMainViewController* mainViewController;

?

readwrite is not strictly necessary, as it is the default. 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.

If you are looking into weak references, I would highly recommend reading this post by Mike Ash. It is important to understand the difference between zeroing weak references and non-zeroing weak references.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM