我正在从swift 2转换为swift 3.我注意到我无法在swift 3中将布尔值转换为整数值:\.
let p1 = ("a" == "a") //true
print(true) //"true\n"
print(p1) //"true\n"
Int(true) //1
Int(p1) //error
Run Code Online (Sandbox Code Playgroud)
例如,这些语法在swift 2中运行良好.但在swift 3中,会print(p1)产生错误.
错误是 error: cannot invoke initializer for type 'Int' with an argument list of type '((Bool))'
我明白为什么错误发生了.任何人都可以解释这种安全性的原因以及如何在swift 3中将Bool转换为Int?
swift3 ×1