Explain the @dynamic and @synthesize commands in Objective-C.
Answer»
@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).