When we create an outlet its property is directly set to a weak type. However weak type contains on optional value. I want outlet created to be of strong type so that it always contains a value. But there is memory management issues and can form strong reference cycles.
Is there any kind of situation where i need to create an outlet of strong type?
Imagine you have created a subclass of UIView
and named it ViewA. Now you are going to create ViewA by means of XIB or storyboard. All the subviews which you are going to add directly inside the ViewA will become weak
property as ViewA will own them and will manage memory allocations by itself of its subview.
But now, if you want to create a ViewB inside the same XIB file where you already have ViewA as file owner and this ViewB is not going to be subview of ViewA, then while creating outlet of ViewB, it is to be noted that it becomes a strong
outlet.
So in short, only the top level objects inside XIB or storyboard becomes strong reference whereas all the subviews inside these top level objects, they become weak reference.
You can read more about it in this Apple documentation
Edit: By creating a ViewB, I meant you drag and drop a UIView into the XIB editor, but not as a subview of already existing ViewA. You create it as an separate object. I have attached a screenshot for understanding. So, in this example, outlets of Button 1, Label 1 and Label 2 will be weak
. Whereas outlets of ViewA and ViewB will be strong
.