I’ve got a method that can take a variable number of arguments.
I’m using variadic commands to get the arguments and store them in an NSMutableDictionary.
The problem is, if I send an int to the method, I get a crash, because NSMutableDictionaries can’t store an int.
What I want to do is make the method check if one of the arguments is an int, and if it is, turn it into an NSNumber before I put it in the dictionary.
But I can’t for the life of me find out how to check for an int.
[I know one answer would be “don’t send an int to the method, only send NSNumbers!” Problem is, that places an obligation on the caller of the method that can’t be determined from the method description alone.]
The type of arguments in variadic lists cannot be checked. It has to be specified by some other way.
For instance,
NSLog()uses the format argument to get type information:%@for an object,%dfor an integer value or%ffor a floating point value.