I want to write a function or directive, such as NSLog (), which accepts any variables, primitives and objects. In this function, I want to distinguish them.
I know how this works for objects:
- (void)test:(id)object { if ([object isKindOfClass:[NSString class]]) ...
but how to distinguish objects from structures or even an integer or float. Something like:
"isKindOfStruct:CGRect" or "isInt"
eg?
Is it possible? I thought, since you can send everything to NSLog (@ "...", objects, ints, structs), should this be possible?
Thanks for any help!
EDIT
My ultimate goal is to realize some kind of polymorphism.
I want to be able to call my function:
MY_FUNCTION(int) MY_FUNCTION(CGRect) MY_FUNCTION(NSString *) ... or [self MYFUNCTION:int]...
and in MY_FUNCTION
-(void)MYFUNCTION:(???)value { if ([value isKindOf:int]) ... else if ([value isKindOf:CGRect]) ... else if ([value isKindOfClass:[NSString class]]) ... }
I know that isKindOf does not exist, and you cannot even execute such methods on primitives. I'm also not sure about "???" The general type of "value" in the function header.
Is it possible?
Django
source share