使用switch,写如下的代码时:
int type = 0;
switch (type) {
case 0:
ViewController *vc = [ViewController new];
[self.navigationController pushViewController:vc animated:YES];
break;
default:
break;
}
Xcode会提示错误:Expected expression
解决办法:在case块开始与结尾加入花括号{ }
,如下
int type = 0;
switch (type) {
case 0:
{
ViewController *vc = [ViewController new];
[self.navigationController pushViewController:vc animated:YES];
}
break;
default:
break;
}
防遗忘
网友评论