Swift Compiler Error Type 'int' does not conform to protocol 'Boolean Type'
2015-07-06 14:55
633 查看
Swift报错: Swift Compiler Error Type 'int' does not conform to protocol 'Boolean Type'
在OC中,用0,1表示bool.习惯了这样的写法:
int i =
1;
if (i) {
}
但是由于Swift的类型安全机制,如果你在需要Bool的地方使用了其他值,在Swift里面是会报错的.
错误代码:
let a =
1
if a {
}
正确代码:
if a ==
1 {
}
在OC中,用0,1表示bool.习惯了这样的写法:
int i =
1;
if (i) {
}
但是由于Swift的类型安全机制,如果你在需要Bool的地方使用了其他值,在Swift里面是会报错的.
错误代码:
let a =
1
if a {
}
正确代码:
if a ==
1 {
}
相关文章推荐
- Swift IOS url Encoding
- swift函数和初始化控件(// MARK:分割线)
- Swift Compiler Error Integer literal overflows when stored into 'UInt8'
- swift base64
- OC与Swift混编
- Swift Compiler Error Binary oprator '+' cannot be applied to operands of type 'UInt16' and 'UInt8'
- swift使用md5
- Swift 2.0语法更新(二)
- Swift 2.0语法更新(一)
- Swift学习资料汇总
- swift * 字符串-String
- Swift的switch结构中,fallthrough的用法注意总结
- 从零开始学Swift (1)
- swift中 类似OC的宏定义
- swift边学边记
- [全国首发]Swift视频教程
- Swift伟大的编程语言数据采集
- Swift开发教程--Swift的基本语法
- Swift中定义二维数组的方法及遍历方法示例
- Swift实现类网易云音乐横向scroll menu切换菜单(二)