Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective c return type switch

I want to use the return type of a selector to determine how it is used in my code is there a way to differentiate the return types in objective c I'll give you an example.

SEL selectors[]=
{@selector(method1),
... //each method returns a different type
@selector(methodn);}  

for (SEL sel in selectors)  
    {
    switch [[self performSelector:sel]/*idk something here maybe?*/]
        {
        case int:
            //do some stuff
        ...
        case NSString *:
            //do some other stuff
        }
     }

Thanks in advance I couldn't find anything anywhere on this that talked about objective c

like image 348
Jordan Medlock Avatar asked Dec 05 '25 14:12

Jordan Medlock


1 Answers

you can do this via method_copyReturnType in objc runtime.

however, objc types for return and parameters are all the same (last i checked), such that the runtime will not return the type with the description "NSArray" -- it will just be the identifier for an objc type. nevertheless, that level of detail is descriptive enough for your int or NSString case, and you can use an NSObject instance's class or isKindOfClass: (etc.) instance methods to determine its type once you have a handle on it.

like image 79
justin Avatar answered Dec 07 '25 05:12

justin