How to save a class variable and then call the static methods of this class in Objective-C

So, I want the class to be able to store the class object and then call the static methods of this class ...

Basically, I have several classes that inherit a single class, so they all have the same static methods (but return different things). I want to be able to store this subclass that I use, so I know which one can be called static methods ...

I know I can get a class with

Class something = [VirginMobile class]; 

But I can’t do something like int i = [something staticMethodReturningInt];

Can I do this?

Greetings

+4
source share
1 answer

I know that you probably do not want to hear this, but as soon as you start to be too smart with classes, this is a sure sign for using ordinary objects. I'm not sure if I understood your question correctly, but one way to solve typing problems is to pass id to the recipient:

 id something = [VirginMobile class]; int i = [something methodReturningInt]; 

This will compile fine if the compiler can see the definition of methodReturningInt . And of course, at run time, VirginMobile has to respond to +methodReturningInt .

+6
source

Source: https://habr.com/ru/post/1441507/


All Articles