Dynamic Method Resolution

Dynamic Method Resolution

  @dynamic directive 用于声明属性的方法dynamic loading,which tells the compiler that the methods associated with the property will be provided dynamically。即编译期不实现此方法,而由动态加载。此directive的作用在于告诉编译器某个类的实例拥有某属性而不会报编译错误。

  You can implement the methods resolveInstanceMethod: and resolveClassMethod: to dynamically provide an implementation for a given selector for an instance and class method respectively. For example:

  

  A class has the opportunity to dynamically resolve a method before the forwarding mechanism kicks in. If respondsToSelector: or instancesRespondToSelector: is invoked, the dynamic method resolver is given the opportunity to provide an IMP for the selector first. If you implement resolveInstanceMethod: but want particular selectors to actually be forwarded via the forwarding mechanism, you return NO for those selectors.

原文地址:https://www.cnblogs.com/tekkaman/p/3551896.html