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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With