Suppose I have the following:
typedef enum functionType {ln, sin, sqrt} functionType;
NSArray *functions = [NSArray arrayWithObjects: @"ln", @"sin", @"sqrt", nil];
Suppose further that *functions will not change at runtime.
Question -- is there any way to set up a single structure which updates both of these? So that I only have to keep track of one list, instead of two.
To explain what is going on -- the idea is that string input from the user will be stored in a variable of type functionType. Later on, I will have code like this:
double valueOfFunction: (functionType) function withInput: (double) input
switch (function) {
case ln:
return ln(input);
case sin:
return sin(input);
case sqrt:
return sqrt(input);
//etc . . . could grow to include a lot of functions.
}
And valueOfFunction needs to be fast. So I don't want to be doing string comparisons there.