Have string represent integer value - Obj C

94 views Asked by At

I have a situation where there are either 4 options or less. The options are A,B,C,D (or it could just be A,C or A,C,D...ect). And each option is associated with a integer value from 0 - 4000. And if all 4 options A,B,C,D are available I want A to represent 0-999, B to represent 1000-1999...ect. If the options are A,C,D I want A = 0-999, C = 1000-2999 & D = 3000-4000, and so on for the different types of options, where I can input the values depending on the options available (Not just spilt evenly). So I could do this with a bunch of if statements but that seems impractical.

if (A & B & C & D) {
    A = 0-999;
    B = 1000-1999;
    ...
}
else if(A & C & D) {
   ...
} //and so on and so on for a lot of combinations

There must be a better way to set this up, and more efficient than a bunch of if statements, how could I go about doing this?

Thanks for the help in advance.

1

There are 1 answers

0
Akshay Karanth On

Keep all your options in an array,

    NSArray *options=@[@"A",@"B",@"C"];
    int i=-1;
    for (NSString *s in options) {
//        Assign your options with Value
        i++;
//      s = i to i+999      Do stuff to assign your value to option.

        i=i+999;

    }

If this is what you want to do.