views:

289

answers:

1

Hi, I have a case where I should get the elements from an array and I do not know if the type is double or integer.

[array objectAtIndex:2]

and the problem is that I can not identify the type. If i knew the type I simply would perform: [[item objectAtIndex:2] intValue] or [[item objectAtIndex:2] doubleValue]

Is there any way to detect that?

Br, Gzim

+2  A: 

See the documentation for the -objCType method.

Basically, it returns a string describing the type contained in the NSNumber. The Objective-C runtime documentation has more information on the type codes.

However, it is quite odd to have a design where the type is unknown. I would suggest that a better solution -- possibly an interesting question -- would be to avoid the ambiguous type in the design of your application.

bbum
I read the reference document over and over, and somehow kept missing objCType. Don't know how that happened, most likely was too late at night for me.
Brandon Bodnár