刚刚更新到最新的Xcode 6.3 Beta 4,我收到的错误似乎无法弄明白。
错误是:
无法调用' CCCrypt'使用类型'的参数列表(CCOperation,CCAlgorithm,CCOptions,UnsafePointer,(Int),nil,UnsafePointer,UInt,UnsafeMutablePointer,(Int),inout UInt)'
使用以下代码:
let keyBytes = UnsafePointer<UInt8>(keyData.bytes)
let keyLength = size_t(kCCKeySizeAES128)
let dataLength = UInt(self.length)
let dataBytes = UnsafePointer<UInt8>(self.bytes)
let bufferData:NSMutableData! = NSMutableData(length:Int(dataLength) + kCCBlockSizeAES128)
var bufferPointer = UnsafeMutablePointer<UInt8>(bufferData.mutableBytes)
let bufferLength = size_t(bufferData.length)
let operation: CCOperation = UInt32(kCCEncrypt)
let algoritm: CCAlgorithm = UInt32(kCCAlgorithmAES128)
let options: CCOptions = UInt32(kCCOptionECBMode)
var numBytesEncrypted: UInt = 0
var cryptStatus = CCCrypt(operation,
algoritm,
options,
keyBytes,
keyLength,
nil,
dataBytes,
dataLength,
bufferPointer,
bufferLength,
&numBytesEncrypted)
这在Beta 3下运行良好,即使在阅读Beta 4更改日志后也不确定发生了什么变化。
不确定问题是什么,我应该打开Apple的错误吗?
答案 0 :(得分:9)
从Xcode 6.3 beta 4发行说明:
C size_t系列类型现在作为Int导入到Swift中 Swift更喜欢将大小和计数表示为带符号的数字, 即使它们是非负面的。这减少了显式的数量 Int和UInt之间的类型转换,更好地与sizeof对齐 返回Int,并提供更安全的算术属性。 (18949559)
因此你必须更换
let dataLength = UInt(self.length)
// ...
var numBytesEncrypted: UInt = 0
通过
let dataLength = self.length // no conversion needed anymore
// ...
var numBytesEncrypted: Int = 0 // or size_t