ok, so i've got this lengthy Switch statement that i'd like to reuse with two different expressions. for both expression, the case constants are the same (they're just integers), but in order to refactor my code i can't seem to get this right, or know if it's even possible.
one expression will rely on the pressing of buttons with tags, while the other relies on the user defaults.
i've attempted setting up an if/else statement before the switch statement assigning values to [sender tag], but that doesn't seem to work.
i've also tried using an NSString to replace the expression, but switch statements don't like that very much, claiming the switch quantity is not an interger
finally, i've tried sending the switch statement the argument of the NSUserDefault, but that wasn't working either, and probably couldn't ever work since the defaults don't have tags.
so, am i absolutly forced to have two identical, lengthy switch statements with the exception of the switch expression? is there no way to make this work?
one expression will rely on the pressing of buttons with tags, while the other relies on the user defaults.
Code:
//first expression
switch ([COLOR="DarkOrange"][sender tag][/COLOR])
{
case (1): [COLOR="Green"]//Do Something[/COLOR]
break;
case (2): [COLOR="green"]//Do Something[/COLOR]
break;
...
//second expression
switch ([COLOR="DarkOrange"][defaults integerForKey:kWhateverKey][/COLOR])
{
case (1): [COLOR="Green"]//Do Something[/COLOR]
break;
case (2): [COLOR="green"]//Do Something[/COLOR]
break;
...
i've attempted setting up an if/else statement before the switch statement assigning values to [sender tag], but that doesn't seem to work.
Code:
if ([defaults intergerForKey:kWhateverKey] == 1)
[sender tag] == 1;
switch ([COLOR="DarkOrange"][sender tag][/COLOR])
{
case (1): [COLOR="Green"]//Do NSUserDefaults Thing[/COLOR]
break;
i've also tried using an NSString to replace the expression, but switch statements don't like that very much, claiming the switch quantity is not an interger
Code:
NSString *switchString = @"[defaults integerForKey:kWhateverKey]";
switch ([COLOR="DarkOrange"]switchString[/COLOR])
{
case (1): [COLOR="Green"]//Do NSUserDefaults Thing[/COLOR]
break;
finally, i've tried sending the switch statement the argument of the NSUserDefault, but that wasn't working either, and probably couldn't ever work since the defaults don't have tags.
Code:
-(void)awakeFromNib
{
[self switchMethod:[defaults integerForKey:kWhateverKey]];
}
-(void)switchMethod:(id)sender
{
switch ([COLOR="DarkOrange"][sender tag][/COLOR])
{
case (1): [COLOR="Green"]//Do Something[/COLOR]
break;
case (2): [COLOR="green"]//Do Something[/COLOR]
break;
...
}}
so, am i absolutly forced to have two identical, lengthy switch statements with the exception of the switch expression? is there no way to make this work?