Objective-c – What’s are the differences between @dynamic and @synthesize

cocoacocoa-touchiphoneobjective c

From the docs I was reading that @dynamic creates the accessor methods at runtime, while @synthesize will create the accessors at build time.

So let me guess: @dynamic saves some memory and code is kept smaller in memory pages? or what? and what other differences are there between these?

Would it be ok to say: "It's always a good idea to use @dynamic rather than @synthesize"? I mean… if that saves really memory, why not?

But I guess @dynamic has some disadvantage over @synthesize, otherwise everyone would just use @dynamic. So what's the drawbacks?

Best Answer

No. dynamic properties don't get generated automatically. @dynamic properties marker indicates to the compiler that you will provide the accessor and setters somehow:

From Objective-C Programming Language Guide:

@dynamic

You use the @dynamic keyword to tell the compiler that you will fulfill the API contract implied by a property either by providing method implementations directly or at runtime using other mechanisms such as dynamic loading of code or dynamic method resolution.