Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the defaults values for @property in iOS?

Tags:

properties

ios

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

like image 995
aneuryzm Avatar asked Apr 27 '11 10:04

aneuryzm


People also ask

What does @property do in Objective C?

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.

What is the use of default value in the properties?

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.

How can we set default value to the variable?

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.


1 Answers

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.

like image 147
Jasarien Avatar answered Sep 28 '22 19:09

Jasarien