当调用[recever message]时,其实执行的是id objc_msgSend(id self, SEL op, ...)这个函数。recever通过isa指针找到当前对象的class,首先到当前class的cache中查找,去过找到,调用op,如果没找到就到methodLists中去查找,如果没有就到super_class中去查找,如此循环直到NSObject。如果在NSObject中仍然没有找到程序不会立即crash,而是会按照优先级执行下类三个方法(高优先级方法消息转发成功后不会再执行低优先级方法)
方案一:+ (BOOL)resolveInstanceMethod:(SEL)sel
+ (BOOL)resolveClassMethod:(SEL)sel
方案二:- (id)forwardingTargetForSelector:(SEL)aSelector
方案三:- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector;
- (void)forwardInvocation:(NSInvocation *)anInvocation;
网友评论