Instead of using else if like this
if([screen isEqualToString :@"A"]){
}
else if(screen isEqualToString:@"B"){
}
Will it work like this
switch ([string isEqualToString:screen]){
case ISA:
break;
case ISB:
break;
default:
break;
}
where ISA and ISB is defined like
#define ISA [screen isEqualToString:A] and **will it be efficient**
No, I most certainly don’t think so. switch/case is all about numeric if/then/else cases.
However what you COULD do is the following:
Write a function and pass it a variable number of arguments (since objective-c implements C look up va_args for the syntax). Pass it the original string and the strings you want to compare to.
Inside that function, use a ‘for’ loop, which compares the strings one by one until it either reaches the end or finds a match according to your criteria.
Once either is met, return the index. And that index you can use in switch case.
A little example:
That should work. Regarding your function: Be sure to either incorporate an Optioncount, or make the options ‘nil’ terminated, because otherwise the function won’t know when the end is actually reached.