Google News
logo
IOS - Interview Questions
Explain the @dynamic and @synthesize commands in Objective-C.
@synthesize : This command generates getter and setter methods within the property and works in conjunction with the @dynamic command. By default, @synthesize creates a variable with the same name as the target of set/get as shown in the below example.

Example1 :
@property (nonatomic, retain) NSButton *someButton;
...
@synthesize someButton;
 
It is also possible to specify a member variable as its set / get target as shown below:

Example2 :
@property (nonatomic, retain) NSButton *someButton;
...
@synthesize someButton= _homeButton;
Here, the set / get method points to the member variable _homeButton.

@dynamic : This tells the compiler that the getter and setter methods are not implemented within the class itself, but elsewhere (like the superclass or that they will be available at runtime). 
Example :
@property (nonatomic, retain) IBOutlet NSButton *someButton;
...
@dynamic someButton;
Advertisement