# How to get object type



## diyora (Aug 18, 2008)

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...


----------



## Captain Code (Aug 18, 2008)

You can ask an object if it's a kind of class:

```
id obj = [myDictionary objectForKey:@"somekey"];
if([obj isKindOfClass:[NSString Class]])
{
//do something
}
else
{
//do some other thing
}
```


----------



## diyora (Aug 19, 2008)

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.


----------



## Captain Code (Aug 19, 2008)

Those are actually typedefs to C data types so they aren't objects
Defined in NSObjCRuntime.h:

```
#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.


----------

