Swift 1.2 (Xcode 6.3 Beta 4) - CCCrypt 无法调用错误

Swift 1.2 (Xcode 6.3 Beta 4) - CCCrypt Cannot Invoke Error

刚刚更新到最新的 Xcode 6.3 Beta 4,我收到一个我似乎无法弄清楚的错误。

错误是:

无法使用类型为“(CCOperation, CCAlgorithm, CCOptions, UnsafePointer, (Int), nil, UnsafePointer, UInt, UnsafeMutablePointer, (Int), inout UInt)”的参数列表调用 'CCCrypt'

使用以下代码:

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 提交错误吗?

来自 Xcode 6.3 beta 4 发行说明:

The C size_t family of types are now imported into Swift as Int, since Swift prefers sizes and counts to be represented as signed numbers, even if they are non-negative. This decreases the amount of explicit type conversion between Int and UInt, better aligns with sizeof returning Int, and provides safer arithmetic properties. (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