Home > DeveloperSection > Forums > @synthesize vs @dynamic, what are the differences?
Samuel Fernandes
Samuel Fernandes

Total Post:156

Points:1096
Posted on    April-27-2015 1:44 AM

 iPhone iPhone  Ios 
Ratings:


 1 Reply(s)
 717  View(s)
Rate this:
What are the differences between implementing a @property with @dynamic or @synthesize?


Mayank Tripathi
Mayank Tripathi

Total Post:397

Points:3117
Supported
Posted on    April-27-2015 4:34 AM

@synthesize will generate getter and setter methods for your property. @dynamic just tells the compiler that the getter and setter methods are implemented not by the class itself but somewhere else (like the superclass or will be provided at runtime).

Uses for @dynamic are e.g. with subclasses of NSManagedObject (CoreData) or when you want to create an outlet for a property defined by a superclass that was not defined as an outlet:

Super class:

@property (nonatomic, retain) NSButton *someButton;
...
@synthesize someButton;
Subclass:

@property (nonatomic, retain) IBOutlet NSButton *someButton;
...
@dynamic someButton;

Don't want to miss updates? Please click the below button!

Follow MindStick