D diyora Registered Aug 18, 2008 #1 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...
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 Moderator Staff member Mod Aug 18, 2008 #2 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 }
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 }
D diyora Registered Aug 19, 2008 #3 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.
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 Moderator Staff member Mod Aug 19, 2008 #4 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.
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.