I am trying to use CommonCrypto (with the help of https://github.com/sergejp/CommonCrypto) for the first time with swift. Here is my code:
UnsafeRawPointer(ivData!.withUnsafeBytes
{(pointer) -> UnsafePointer<Any> in
let ivBuffer = pointer
})
The error is:
Cannot convert value of type 'UnsafePointer' to expected argument type 'UnsafePointer<_>'
What does the <_>
signify? What do I need to do? Thanks.
It's pointer
that it is complaining about. You need to cast it. Here's an example usage, part of creating an MD5 hash:
var rawBytes = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
let _ = data.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) in
CC_MD5(bytes, CC_LONG(data.count), &rawBytes)
}