Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift - Cannot convert value of type 'UnsafePointer<Any>' to expected argument type 'UnsafePointer<_>'

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.

like image 988
ewizard Avatar asked Sep 01 '25 16:09

ewizard


1 Answers

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)
    }
like image 141
Don Avatar answered Sep 07 '25 07:09

Don