ios switch中case中声明变量报错“expected expression”
2015-11-24 16:33
537 查看
最近在写一个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; } }
相关文章推荐
- PHP8新特性之match表达式
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 三个有用的 Switch 命令
- js 中的switch表达式使用示例
- 讲解iOS开发中基本的定位功能实现
- js判断客户端是iOS还是Android等移动终端的方法
- IOS开发环境windows化攻略
- 浅析iOS应用开发中线程间的通信与线程安全问题
- 检测iOS设备是否越狱的方法
- .net平台推送ios消息的实现方法
- php中switch与ifelse的效率区别及适用情况分析
- c#中switch case的用法实例解析
- Go语言中的switch用法实例分析
- php switch语句多个值匹配同一代码块应用示例