When should a weak or strong classifier be used with IBOutlets?

Possible duplicate:
Should IBOutlets be strong or weak in ARC?

In the documentation, I read "Sockets should generally be weak, except for those that belong to the file owner, for the top-level objects in the nib file (or in iOS, the storyboard scene), which should be strong."

Examples? I do not understand when it is better to use the "weak" instead of the "strong" property for IBOutlet.

+4
source share
1 answer

In general: if you create an output in the subtitle of the ViewControllers submatrix, it should be weak. An object exists as long as a top view exists (between viewDidLoad and viewDidUnload). Since iOS 5 ARC automatically resets weak links, when the viewController unloads its view and the view hierarchy is destroyed, your outlet automatically sets to zero.

But maybe you want to create another object in your nib file (model object). Since this object is not under the hierarchy of views, you need to do the iboutlet syntax. If you make it loosely coupled, the object will be auto-implemented, since no other object will have a strong link with it, and ARC will release it and set nil to your IBOutlet. This does not apply to the subspecies, as its supervisor maintains a strong relationship with him.

+24
source

Source: https://habr.com/ru/post/1381738/


All Articles