ios switch中case中声明变量报错“expected expression”

      最近在写一个switch语句的时候,在case块中声明了一个变量,xcode报错“expected expression”,找了很久也没找到语法错误,后来才发现Object-C在case块中声明变量需要用大括号包围,如果没有变量声明就不需要了。

    原报错语句:

switch (button.tag) {
        case 41:
            FaceToFaceReceiptViewController *ftfRVC = [[FaceToFaceReceiptViewController alloc] init];
            [self.navigationController pushViewController:ftfRVC animated:YES];
            [ftfRVC release];
            break;
  

加上大括号后就正常了,无变量声明无需大括号:

    int i,j,jk;
    switch (button.tag) {
        case 41:{
            FaceToFaceReceiptViewController *ftfRVC = [[FaceToFaceReceiptViewController alloc] init];
            [self.navigationController pushViewController:ftfRVC animated:YES];
            [ftfRVC release];
            break;
        }      
        case 42:{
            FaceToFacePaymentViewController *ftfPVC = [[FaceToFacePaymentViewController alloc] init];
            [self.navigationController pushViewController:ftfPVC animated:YES];
            [ftfPVC release];
            break;
        }
        case 3:
            i = 4;
            j = 3;
            jk = 0;
            break;
            
        default:
            break;
    }
}





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值