switch...case 基本語法格式:ssr
switch (表達式){
case 值1 : 語句1 break;
case 值2 : 語句2 break;
...
default : 語句n break;
}
從表達式值等於某個case語句後的值開始,它下方的全部語句都會一直運行,直到遇到一個break爲止。假如任何一個case語句的值都不等於表達式的值,就運行可選標籤default之下的語句。ip
在oc中的應用以下:it
switch (status.user.verified_type) {語法
case -1:im
self.verified_type_image.image = nil;vi
break;標籤
case 0:cas
self.verified_type_image.image = [UIImage imageNamed:@"avatar_vip"];tar
break;
case 2:
self.verified_type_image.image = [UIImage imageNamed:@"avatar_enterprise_vip"];
break;
case 3:
self.verified_type_image.image = [UIImage imageNamed:@"avatar_enterprise_vip"];
break;
case 5:
self.verified_type_image.image = [UIImage imageNamed:@"avatar_enterprise_vip"];
break;
case 220:
self.verified_type_image.image = [UIImage imageNamed:@"avatar_grassroot"];
break;
default:
self.verified_type_image.image = nil;
break;
}