iOS底层---复写resolveInstanceMethond,且未添加IMP的情况下,会调用两次?

441 阅读1分钟

图中D步骤的methodSignatureForSeletor会调用class_getInstanceMethod去查找方法,然而在用class_getInstanceMethod中如果没有发现IMP,则会最后调用一次resolveInstanceMethond

// No implementation found. Try method resolver once.

    if (resolver  &&  !triedResolver) {
        runtimeLock.unlock();
        _class_resolveMethod(cls, sel, inst);
        runtimeLock.lock();
        // Don't cache the result; we don't hold the lock so it may have 
        // changed already. Re-do the search from scratch instead.
        triedResolver = YES;
        goto retry;
    }