Document directory
@ Dynamic refers to the Code provided by developers: setter is required for read-only attributes, and setter and getter are required for read/write attributes.
@ Synthesize indicates that, unless the developer has already done this, the compiler generates the corresponding code to satisfy the attribute declaration.
After reading some documents, confirm @ dynamic to tell the compiler that the methods for obtaining and assigning attributes are implemented by the user and are not automatically generated.
@ Dynamic just tells the compiler that the getter and setter methods are implemented not by the class itself but somewhere else (like the superclass)
Looking at Apple's official documentation, it seems more interesting:
Dynamic Method parsing sometimes requires dynamic implementation of a method. For example, the modifier @ dynamic propertyname before the attribute in objective-C (refer to the attribute section in objective-C 2.0 programming language; indicates that the compiler must dynamically generate the corresponding method for this attribute. You can implement resolveinstancemethod: And resolveclassmethod: to dynamically implement the object methods or class methods for a given object. The objective-C method can be considered as having at least two parameters -- Self and _ cmd --
. You can use the class_addmethod method to add a function to the class method. For example, there are the following functions: void dynamicmethodimp (ID self, Sel _ cmd) {// implementation ....} You can use handler: to implement resolvethismethoddynamically as a class method: @ implementation myclass + (bool) handler :( SEL) Asel {If (Asel = @ selector (resolvethismethoddynamically )) {class_addmethod ([self class], Asel, (IMP) dynamicmethodimp, "V @:"); Return yes;} return [Super resolveinstancemethod: Asel];} @ end generally, message Forwarding (see "message forwarding") and dynamic method parsing are irrelevant. Before entering the message forwarding mechanism, respondstoselector: And instancesrespondtoselector: Will be called first. You can provide an imp for the selected token in the two methods. If you have implemented the resolveinstancemethod: method but still want the normal message forwarding mechanism to be implemented, you only need to return no. Department. m in chapter 30 of cocoa programming for Mac OS X written by Aaron hillegass also uses the dynamic method, that is, the key-value coding method. Source: http://blog.sina.com.cn/s/blog_6f92e3580100zx5s.html