How to get object type

diyora

Registered
Hello,
I want to know the object type in cocoa.
Suppose object (id) is consider in which i store string,int,etc..
But i want to know the type of (id).

Thank you...
 
You can ask an object if it's a kind of class:
Code:
id obj = [myDictionary objectForKey:@"somekey"];
if([obj isKindOfClass:[NSString Class]])
{
//do something
}
else
{
//do some other thing
}
 
Thanks for your kind reply.

This is ok for NSString and like wise Class type.
But what aboout NSInteger, NSUInteger, etc. basic types?
It is not working with NSInteger.
Any other way?

Thanks.
 
Those are actually typedefs to C data types so they aren't objects
Defined in NSObjCRuntime.h:
Code:
#if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
typedef long NSInteger;
typedef unsigned long NSUInteger;
#else
typedef int NSInteger;
typedef unsigned int NSUInteger;
#endif

The best way would probably be instead to use NSNumber because that is an object. So return only objects and you can use the class testing that way.
 
Back
Top