3

Just updated to the latest Xcode 6.3 Beta 4 and I'm getting an error I cannot seem to figure out.

There error is:

Cannot invoke 'CCCrypt' with an argument list of type '(CCOperation, CCAlgorithm, CCOptions, UnsafePointer, (Int), nil, UnsafePointer, UInt, UnsafeMutablePointer, (Int), inout UInt)'

With the following code:

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)

This was working great under Beta 3 and not sure what has changed, even after reading the Beta 4 change log.

Not sure what the issue is, should I open a bug with Apple?

Mavro
  • 571
  • 8
  • 19

1 Answers1

9

From the Xcode 6.3 beta 4 release notes:

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)

Therefore you have to replace

let dataLength    = UInt(self.length)
// ...
var numBytesEncrypted: UInt = 0

by

let dataLength    = self.length // no conversion needed anymore
// ...
var numBytesEncrypted: Int = 0 // or size_t
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382