Data type in a NSNumber
Into a NSNumber you can put primitives like int, bool, float, etc... They are translated in a Objective-C object (the NSNumber).
If you want to get the type of data contained into the NSNumber, the objCType method can help you.
- (const char *)objCType
It returns a C string (const char *) containing the Objective-C type. The objCType method is declared in the NSValue class.
Finally, using the strcmp function you can understand if the data type. How is explained below.
const char *t = [myNSNumber objCType]; if (strcmp("i", t) == 0) { NSLog(@"is a int"); return; } if (strcmp("f", t) == 0) { NSLog(@"is a f"); return; } if (strcmp("d", t) == 0) { NSLog(@"is a dobule"); return; } if (strcmp("c", t) == 0) { NSLog(@"WARNING! is a boolean or a char!!!!!"); return; }
That's all!














