OC中的方法調(diào)用,其實(shí)都是轉(zhuǎn)換為objc_msgSend函數(shù)的調(diào)用
objc_msgSend的執(zhí)行流程可以分為3大階段
消息發(fā)送
動(dòng)態(tài)方法解析
消息轉(zhuǎn)發(fā)


///
+(BOOL)resolveInstanceMethod:(SEL)sel
{
? If(sel == @selector(test)){
? Method method = class_getInstanceMethod(self,@selector(other));
class_addMethod(self,sel,method_getImplementation(method),
? method_getTypeEncoding(method));
? return YES;
? }
return [super resolveInstanceMethod:sel];
}
Void other(id self, SEL _cmd)
{
? NSLog(@“%@-%s-%s”,self,sel_getName(_cmd),__func__);
}
+(BOOL)resolveInstanceMethod:(SEL)sel
{
? If(sel == @selector(test)){
? class_addMethod(Self,sel,(IMP)other,@“v@:”);
? return YES;
? }
? return [super resolveInstanceMethod:sel];
}
///
Method 可以理解為等價(jià)于struct method_t*

生成NSMethodSignature
NSMethodSignature * signature = [NSMethodSignature signatureWithObjCTypes : “i@:i”];
NSMethodSignature * signature = [[[MJStudent alloc] init] methodSignatureForSelector:@selector(test:)];