I want to do some simple arithmetic in NSNumbers and save the type. Is it possible?
For instance:
- (NSNumber *)add:(NSNumber *)firstNumber to:(NSNumber *)secondNumber;
Is the definition of my method, and firstNumber and secondNumber are integers, then I would like to return an integer, which is their integer. Similarly, if both are doubles, then to return the result as a double.
It looks like I can get the type (other than the boolean) using [NSNumber objCType]
found in this question: get the type NSNumber , but I can't seem to extract these types and do the calculations without a lot of code to extract the values, do the calculation and return the result for each possible type.
Is there a short and concise way to do this?
source share