If you declare an object using @property in the header file, then you have to synthesize it using @synthesize in the implementation file.
@interface ExampleClass : NSObject
@property (nonatomic, retain) NSString *name;
Now the compiler will synthesize accessor methods for name.
ExampleClass *newObject=[[ExampleClass alloc]init];
NSString *name1=[newObject name]; // get 'name'
- List of attributes of @property :
- retain: 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 autorelease pool.
readonly: If you don't want to allow the property to be changed via setter method, you can declare the property readonly.
@property (readonly) NSString *name;
is a replacement for retain.
@property (nonatomic, strong) AVPlayer *player;
- unsafe_unretained: There are a few classes in Cocoa and Cocoa Touch that don’t yet support weak references, which means you can’t declare a weak property or weak local variable to keep track of them. These classes include NSTextView, NSFont and NSColorSpace,etc. If you need to use a weak reference to one of these classes, you must use an unsafe reference.
An unsafe reference is similar to a weak reference in that it doesn’t keep its related object alive, but it won’t be set to nil if the destination object is deallocated.
@property (unsafe_unretained) NSObject *unsafeProperty;