Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is @dynamic in iPad/iPhone

I am jus wondering what is mean by @dynamic in objective-c and how it works.any help please

like image 708
Hariprasad Avatar asked Mar 25 '11 13:03

Hariprasad


1 Answers

@dynamic means that you will provide an implementation of those methods dynamically at run time.

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtDynamicResolution.html

has all the details, but basically using @dynamic means that you promise to provide implementations for the property promised methods at runtime.

In particular look here;

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html

for an example of how you'd construct your dynamic method and place it into the runtime.

Core Data uses this mechanism to provide the accessors. It's quite amazingly cool, once you dig into it :)

And as a side note, meta-programming in ObjC is not for the faint of heart, don't ship it till you grok it, otherwise your users will suffer.

like image 184
Bill Dudney Avatar answered Sep 28 '22 02:09

Bill Dudney