Is there a more intelligent way to rewrite this?
if ([cardName isEqualToString:@\"Six\"]) {
[self setValue:6];
} else if ([cardName isEqualToString:@\"Se
There are other ways to do that, but switch
isn't one of them.
If you only have a few strings, as in your example, the code you have is fine. If you have many cases, you could store the strings as keys in a dictionary and look up the corresponding value:
NSDictionary *cases = @{@"Six" : @6,
@"Seven" : @7,
//...
};
NSNumber *value = [cases objectForKey:cardName];
if (value != nil) {
[self setValue:[value intValue]];
}