Objective-c: How can I get Class instance in class method

前端 未结 2 1029
耶瑟儿~
耶瑟儿~ 2020-12-20 17:46

I have 2 classes, Parent and Child, and Parent has a class method named func. Now I want to get Class instance in func method to distinguish which class is caller.



        
2条回答
  •  眼角桃花
    2020-12-20 18:29

    To get the current class object, you should be able to do:

    [self class];
    

    As self will refer to the class instance, because it's a class method. Class is a method defined in NSObject, which returns the class for the object.

    Edited to avoid confusion...

提交回复
热议问题