How to check if a variable is an object?

Posted by Patrick on Stack Overflow See other posts from Stack Overflow or by Patrick
Published on 2012-06-01T04:37:22Z Indexed on 2012/06/01 4:40 UTC
Read the original article Hit count: 89

Filed under:

Is there any way to do the following at compile-time?

int anInteger = 0;
__if_object(anInteger) {
    // send object some messages
}
__if_primitive(anInteger) {
    // do something else
}

An dummy situation where this could be used is to define the __add_macro below.

#define __add_macro(var, val) __something_goes_here__

int i = 1;
MyInteger* num = [[MyNumber alloc] initWithValue:1]

__add_macro(i, 4);
__add_macro(num, 4);

// both should now hold 5

Thanks

© Stack Overflow or respective owner

Related posts about objective-c