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
NOTE: Yes I'm using KVO so I am recieving a string in the "callback."
NOTE #2 Electric boogaloo: So what made me first consider the switch statement is my original code implementation was like this:
if ([keyPath isEqual:@"refreshCount"] && ([[change valueForKey:@"new"] intValue] == 10)) { //
NSLog(@"achievemnt hit inside");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"title" message:@"Achievement Unlocked!" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:nil];
[alert show];
I want to do a bunch of these with different XX values all in the same method:
if ([keyPath isEqual:@"refreshCount"] && ([[change valueForKey:@"new"] intValue] == 10)) {
//unlock small achievement
}
if ([keyPath isEqual:@"refreshCount"] && ([[change valueForKey:@"new"] intValue] == 50)) {
//unlock bigger achievement
}
//etc
This just seemed very inefficient to me but maybe I'm wrong.