Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's are the differences between @dynamic and @synthesize?

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?

like image 484
openfrog Avatar asked Jan 14 '10 17:01

openfrog


1 Answers

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.

like image 110
notnoop Avatar answered Nov 12 '22 00:11

notnoop