swift - 如何在 Swift 2 中将 UInt8 转换为 Bool

标签 swift boolean

我不得不重做我使用在 Swift 1.2 中工作的 boolean 值的所有代码。现在在 Swift 2.0 中,我可以正确使用 Bool,但我不清楚如何将 UInt8 (0/1) 转换为 Swift Bool。

例子:

 let timeDateValid:Bool = bytes[0]

错误信息: 无法将类型“UInt8”转换为指定类型“Bool”

谢谢!

最佳答案

只要测试它是否为0:

let timeDateValid:Bool = (bytes[0] != 0)

关于swift - 如何在 Swift 2 中将 UInt8 转换为 Bool,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32663168/

相关文章:

java - 检查三个 boolean 值中的至少两个是否为真

ios - 如果找到搜索栏文本,则更改表格 View 的字母颜色

ios - WatchOS3中SKShapeNode添加手势

java - 测试给定字符串中的两对

java - Java中使用compareTo进行排序

algorithm - 从 16 位值中逐行扫描位

javascript - 在 kendo.ui.GridColumn 中格式化日期和 boolean 值

ios - 错误 : Value of type 'AppDelegate?' has no member 'present'

swift - ViewController 中的 CustomCell 标签不显示数据

ios - 实例成员 '....' 不能用于类型 'CustomTextField' ;您的意思是使用这种类型的值吗?