Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
尝试使用 Swift 变得可笑了。我将 Xcode 从 6.2 更新到 6.3,现在编译器抱怨简单的添加。源代码是这样的,其中 passKeyData 是一个 NSData 项:
let u8Value : UInt8 = 3 + passKeyData.length as UInt8 + 1
斯威夫特抱怨“'+' 运算符的模糊使用”。
这是一个有点误导性的错误信息,但是......
NSData.length返回 an Int,并且您不能从Intvalue 转换为UInt8using as。你需要明确地构造一个UInt8这样的:
NSData.length
Int
UInt8
as
let u8Value : UInt8 = 3 + UInt8(passKeyData.length) + 1
您可能还想检查该值是否不超过UInt8.max(否则您将遇到运行时失败),或者UInt8(truncatingBitPattern: x)如果您不介意将其截断以适合,请使用。
UInt8.max
UInt8(truncatingBitPattern: x)