iPhone OS: making a switch statement that uses string literals as comparators instead of integers
Posted
by nickthedude
on Stack Overflow
See other posts from Stack Overflow
or by nickthedude
Published on 2010-05-25T17:31:55Z
Indexed on
2010/05/25
17:41 UTC
Read the original article
Hit count: 271
So i'd like to do this:
switch (keyPath) {
case @"refreshCount":
//do stuff
case @"timesLaunched":
//do other stuff
}
but apparently you can only use integers as the switch quantity. Is the only way to do this parse the string into an integer identifier and then run the switch statement?
like this:
nsinteger num = nil;
if (keyPath isEqual:@"refreshCount") {
num = 0
}
if (keyPath isEqual:@"timesLaunched") {
num = 1
}
I'm trying to optimize this code to be as quick as possible because its going to get called quite often.
thanks,
Nick
© Stack Overflow or respective owner