Discover subclasses of a given class in Obj-C

后端 未结 5 1292
北海茫月
北海茫月 2020-12-16 21:15

Is there any way to discover at runtime which subclasses exist of a given class?

Edit: From the answers so far I think I need to clarify a bit more

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-16 21:44

    Rather than try to automatically register all the subclasses of MYCommand, why not split the problem in two?

    First, provide API for registering a class, something like +[MYCommand registerClass:].

    Then, create code in MYCommand that means any subclasses will automatically register themselves. Something like:

    @implementation MYCommand
    + (void)load
    {
        [MYCommand registerClass:self];
    }
    @end
    

提交回复
热议问题