@SYNTHESIZE VS @DYNAMIC, WHAT ARE THE DIFFERENCES?

Samuel Fernandes

Total Post:159

Points:1117
Posted by  Samuel Fernandes
iPhone  Ios 
 1174  View(s)
Ratings:
Rate this:
What are the differences between implementing a @property with @dynamic or @synthesize?
  1. Mayank Tripathi

    Post:397

    Points:3117
    Re: @synthesize vs @dynamic, what are the differences?

    @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;

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!