在某些情况下,我们需要动态的向一个类插入一个实例方法(也可以是一个类方法):这时我们可以用class_addMethod函数来完成: BOOL class_addMethod ( Class cls, SEL name, IMP imp, const char *types ); 在Objective-C Runtime Reference 中可以看到各个参数的含义: Parameters **cls** The class to which to add a method. **name**…