Check if subclass overrides a method

前端 未结 7 2275
耶瑟儿~
耶瑟儿~ 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:57

    Not the optimal solution but you can keep a boolean member to your UIView subclass (let's call it UIViewSub indicating if the desired behavior is implemented by the class and check that boolean before using the method.

    Your subclasses (those inheriting UIViewSub) will set/unset this member accordingly in its construction (i.e if it does override it with implementation or not)

提交回复
热议问题