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
See the documentation for the
-objCTypemethod.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.