Can anyone provide me link or information about :
why weak
variable is beneficial as compared to strong variable?
and IBOutlets
in ARC
, that should be weak
or strong
? Why delegate is also defined as weak property?
Thanks in advance.
Can anyone provide me link or information about :
why weak
variable is beneficial as compared to strong variable?
and IBOutlets
in ARC
, that should be weak
or strong
? Why delegate is also defined as weak property?
Thanks in advance.
The weak like the world is weak retain to object, when it dealloc that will be nil, and we can avoid the retain cycle. IBOutlets property because the view had retain it so that needn't strong retain it again.
strong: assigns the incoming value to it, it will retain the incoming value and release the existing value of the instance variable
weak: will assign the incoming value to it without retaining it.
The current recommended best practice from Apple
is for IBOutlets
to be strong unless weak is specifically needed to avoid a retain cycle
.
In general you should make your outlet strong, especially if you are connecting an outlet to a subview
or to a constraint that's not always going to be retained by the view hierarchy
. The only time you really need to make an outlet weak is if you have a custom view
that references something back up the view hierarchy and in general that's not recommended.