0

I have read about "@dynamic" keyword of objectiveC in various blog. But I couldn't get a clear idea about it and how it is compared with "synthesize". Many peoples were explained in the blogs that getter methods and setter methods are created during run time. Is there any other answer how "dynamic" is working in iOS? I would like to how it is really working? Also why the @dynamic keyword is used for property declared in NSMangedObject instead of @synthesize? Can anyone help me to get a clear understanding on this.

sree_iphonedev
  • 3,514
  • 6
  • 31
  • 50

1 Answers1

1

@dynamic tells the compiler that you, the developer, will make sure that implementations of properties will be added at runtime. There is no hint how you would do this (I suppose it requires playing around with the internals of the Objective-C runtime in objc/runtime.h), and since there is no hint how you do this, you can't use @dynamic in code that you write. Unless you figure it out yourself and post the answer here :-)

NSManagedObject contains @dynamic because its properties are created at runtime by Core Data, and not by the Objective-C compiler. The Objective-C compiler wouldn't know how to create these properties, since they access the database behind the programmer's back.

gnasher729
  • 51,477
  • 5
  • 75
  • 98
  • Thanks gnasher for answering specific to my question. But can u make clear the point, properties are created at runtime by Core Data? Does that mean the core data framework is managing this case? Also did you mean properties access the database behind the programmer's back? – sree_iphonedev Nov 23 '15 at 17:41