What is property strong/weak for?


Instance variables can have __weak.

 __weak BNRItem *container;

Still, properties can have weak as well.

 @property (nonatomic, weak) BNRItem *container;

I don’t know why the “weak” exists in both. Thank you.


Typically, you create a property, synthesize it, and do not create the instance variable (because it is automatically created for you when synthesized). Thus, declaring a property to be weak means that the instance variable that backs it is also declared as weak.

Sometimes, you have a property that you either don’t synthesize at all or you synthesize it to point at another instance variable. In these cases, the instance variable must have the same storage specifier (__strong, __weak, etc.) as the property (strong, weak, etc.)


Ah, I got it.
I seem to have forgotten the case that those instance variable can be scratched out.
Thank you for explanation, JoeConway!