typedef struct {
int x, y;
} Point;
//C switch works only with integers:
//tuple matching becomes explicit checks
NSString *describe(Point p) {
if (p.x == 0 && p.y == 0) {
return @"(0, 0) point";
}
if (p.y == 1) {
return [NSString stringWithFormat:
@"(%d, 1) point", p.x];
}
if (p.x == 1) {
return [NSString stringWithFormat:
@"(1, %d) point", p.y];
}
if (p.x == p.y) {
return [NSString stringWithFormat:
@"(%d, %d) point", p.x, p.y];
}
return @"other point";
}
Point point = {5, 5};
NSString *str = describe(point);
//str is "(5, 5) point"