venerdì 14 marzo 2014

@synthetize vs @dynamic in ObjectiveC

Since it's the second or third time that I find myself looking for a response to this question on Internet, I'd like to note it here and share with everyone who needs an explication of the difference between the to directives @dynamic and @syntethize in Objective C.

The response is posted by Alex Rozanski in a Stackoverflow thread

Some accessors are created dynamically at runtime, such as certain ones used in CoreData's NSManagedObject class. If you want to declare and use properties for these cases, but want to avoid warnings about methods missing at compile time, you can use the @dynamic directive instead of @synthesize.
...
Using the @dynamic directive essentially tells the compiler "don't worry about it, a method is on the way."
The @synthesize directive, on the other hand, generates the accessor methods for you at compile time (although as noted in the "Mixing Synthesized and Custom Accessors" section it is flexible and does not generate methods for you if either are implemented).

Nessun commento:

Posta un commento