@Property directive is to make it easy to
create and configure properties by automatically generating these "accessors
methods". It allows you to specify the behavior of a public property on a
semantic level, and it takes care of the implementation details for you . @Property are atomic by default.Accessors methods - Getters and Setters
List of Attributes
- Atomic (default) & Non Atomic
- Retain (default) or Strong
- Assign (default) & Copy
- Weak
- Readonly & ReadWrite (default)
1) Atomic & Non Atomic
A) Atomic is the default behavior. If an object is
declared as atomic then it becomes thread-safe. Thread-safe means, at a
time only one thread of a particular instance of that class can have the
control over that object.
If the thread is performing getter method then other thread cannot perform setter method on that object. It is slow.
B) Nonatomic is not thread-safe. You can use the non-atomic property attribute to specify that synthesized accessors
simply set or return a value directly, with no guarantees about what
happens if that same value is accessed simultaneously from different
threads.
For this reason, it’s faster to access a non-atomic property than an atomic one.
2) Retain or Strong
Create an owning relationship between the property and the assigned
value. This is the default for object properties.
Retain or Strong is required when the attribute is a pointer to an object.The setter method will increase retain count of the object, so that it will occupy memory in auto-release pool.
3) Assign
The assign attribute doesn’t perform any kind of
memory-management call when assigning a new value to the property. This is the
default behavior for primitive data types.
4) Weak
Weak Create a non-owning relationship between the property and the
assigned value. Use this to prevent retain cycles . The Retain count is not increase .
5) ReadOnly
Readonly If you don't want to allow the property to be changed via setter method, you can declare the property readonly. Compiler will generate a getter, but not a setter.
No comments:
Post a Comment