Check if subclass overrides a method

前端 未结 7 2264
耶瑟儿~
耶瑟儿~ 2021-02-09 13:15

Is it possible to check whether a subclass implements a method that exists either in its immediate superclass or in some superclass of its superclass, etc?

E.g. I subcla

7条回答
  •  执笔经年
    2021-02-09 13:50

    Expanding on ZeMoon's answer, I found that there wasn't enough logic to satisfy all cases. I needed to add a check to ensure that instances of the next superclass in the loop implement the specified selector at all. Subclasses of UIView are one example.

    while (objSuperClass != Nil) {
        isMethodOverridden = ([objSuperClass instancesRespondToSelector:selector]) && 
                             ([object methodForSelector:selector] !=
                              [objSuperClass instanceMethodForSelector:selector]);
    
        if (isMethodOverridden) {
    
        }
    }
    

提交回复
热议问题