//switch expression analog: a function
//with a C switch; grouped cases play
//the role of ranges
NSString *describeSize(int inchSize) {
switch (inchSize) {
case 14: case 15:
return @"too small";
case 16: case 17: case 18:
return @"good for the past decade";
case 19: case 20: case 21:
case 22: case 23:
return @"for office work";
case 24: case 25: case 26: case 27:
return @"great choice";
default:
return @"are you sure this isn't a TV?";
}
}
NSString *str = describeSize(24);
//str is "great choice"
| Swift provides a shorthand spelling of switch that you can use when setting values. |