Featured post

Difference between protocol and delegates?

A protocol, declared with the ( @protocol syntax in Objective-C) is used to declare a set of methods that a class "adopts" (de...

Thursday, 9 April 2015

Properties in objective C

Properties:-
An object’s properties let other objects inspect or change its state. But, in a well-designed object-oriented program, it’s not possible to directly access the internal state of an object. Instead, accessor methods (getters and setters) are used as an abstraction for interacting with the object’s underlying data.

The goal of the @property directive is to make it easy to create and configure properties by automatically generating these accessor methods. It allows you to specify the behaviour of a public property on a semantic level, and it takes care of the implementation details for you.

This module surveys the various attributes that let you alter getter and setter behaviour. Some of these attributes determine how properties handle their underlying memory, so this module also serves as a practical introduction to memory management in Objective-C

Property Attributes Indicate Data Accessibility and Storage Considerations

Lets go through the details about these following attributes:

(a). atomic  (default)
(b). nonatomic
(c). strong=retain (default)
(d). weak= unsafe_unretained
(e). retain
(f). assign (default)
(g). unsafe_unretained
(h). copy
(g). readonly
(i). readwrite (defalut)

01.What is atomic in Objective C ?
Answer:-
 
-Atomic means only one thread access the variable(static type).
-Atomic is thread safe.
-but it is slow in performance
-atomic is default behavior
-Atomic accessors in a non garbage collected environment (i.e. when using retain/release/autorelease) will use a lock to
ensure that another thread doesn't interfere with the correct setting/getting of the value.
-it is not actually a keyword.

Example :
@property (retain) NSString *name;
@synthesize name;
Related:



No comments:

Post a Comment