I have a function which I would like to take in an NSString and an int arguments and then use the switch statement in order to return a calculated value, as in multiply the int by some constant, depending on what NSString is supplied.
Obviously, a switch statement doesn’t work for objects in Objective-C. So what is the fastest alternative? Is it if-else statements? Or is there a more elegant method?
EDIT
The reason why I care about performance is that I am modifying UI elements the user is watching as the ultimate result of these calculations and I don’t want that to feel sluggish.
Don’t optimize prematurely. Just make an NSDictionary that maps each string to its multiplier. Then see if that’s fast enough.
If you need to do a different operation depending on the string, make each value in the dictionary a block that performs the appropriate operation.