@dynamic

Definitions

@synthesize will generate the getter and setter methods of the properties if the getter and/or setter has not already been implemented manually. This is what you currently believe @dynamic does.

@dynamic is used when you don’t want the runtime to automatically generate a getter and setter AND you haven’t implemented them manually. Basically, @dynamic is telling the compiler that the getter/setter will be provided dynamically at runtime or provided elsewhere, like a base class.

Usage

Since @dynamic means that the getter and setter methods are implemented elsewhere. One of the ways is to have runtime look for them in a Base class.

For example, say we have a Base class, and we implement the getter/setter methods like so:

When we use self.publicAge, we use the getter/setter properties generated by the compiler. If we want to manipulate the instance variable itself, we use _publicAge.

Same goes for publicName.

If we want to write our own customizable methods, we’d do:

In which case we over-ride the get/set methods generated by the compiler with our own custom get set methods. Whether you want to use the generated or your own custom methods is both fine, depending on your needs.

Using @dynamic

Now this is where using @dynamic comes in.

Say you have a class Child1, which is derived from the Base class.

@dyanmic means the getter/setter methods are implemented by the self class, but somewhere else
like superclass (Base), or be provided at runtime.

Hence when you use the properties

they will use Base’s publicAge and publicName getter/setter methods.