Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在我的实现中,我可以选择使用 class_addMethod 在运行时创建新方法,或者我可以依赖 forwardInvocation/NSProxy。当这两种方法都可以作为解决方案时,您更喜欢哪种方法以及如何确定?
我更喜欢class_addMethod.
class_addMethod
forwardInvocation
NSInvocation
class_addMethod是最好的选择。因为它可以使用方法搜索缓存来改进查找匹配方法地址。
参考自:BOOK“Effective Objective-C 2.0”第 12 期