What are the defaults values for @property in iOS ?
For example, if I declare @property NSString* photographer;
is the default value (assign) or (retain) or what else ?
(atomic, non-atomic) ?
I cannot find this information from the documentation. thanks
The goal of the @property directive is to configure how an object can be exposed. If you intend to use a variable inside the class and do not need to expose it to outside classes, then you do not need to define a property for it. Properties are basically the accessor methods.
Note: The default value is the value specified in the HTML value attribute. The difference between the defaultValue and value property, is that defaultValue contains the default value, while value contains the current value after some changes have been made.
You can set the default values for variables by adding ! default flag to the end of the variable value. It will not re-assign the value, if it is already assigned to the variable.
I believe the defaults are (atomic, assign)
, however, you should not leave them empty.
The default may change at any point, and you're writing code that is relying on the definition of the property.
For example, if you rely on the default assign
and it changes to retain
for whatever reason in the future, then all of your code is going to leak.
Conversely, if the default is retain and you rely on that and it changes to assign, then your code is going to crash when you inevitably over release an object.
Do not rely on any default, regardless of what they may be.
Explicitly define your properties' attributes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With