C class overrides a method

This question already has an answer here:

  • Objective-C detect if class overrides inherited method 2 answers

  • You just need to get a list of the methods, and look for the one you want:

    #import <objc/runtime.h>
    
    BOOL hasMethod(Class cls, SEL sel) {
        unsigned int methodCount;
        Method *methods = class_copyMethodList(cls, &methodCount);
    
        BOOL result = NO;
        for (unsigned int i = 0; i < methodCount; ++i) {
            if (method_getName(methods[i]) == sel) {
                result = YES;
                break;
            }
        }
    
        free(methods);
        return result;
    }
    

    class_copyMethodList only returns methods that are defined directly on the class in question, not superclasses, so that should be what you mean.

    If you need class methods, then use class_copyMethodList(object_getClass(cls), &count) .

    链接地址: http://www.djcxy.com/p/84570.html

    上一篇: 如何在运行Android的Chrome App中接收UDP广播数据包

    下一篇: C类覆盖了一种方法