Swift - 无法转换类型的值&#39; UnsafePointer <any>&#39;预期参数类型&#39; UnsafePointer&lt; _&gt;&#39;

时间:2017-12-04 20:30:52

标签: swift pointers encryption types commoncrypto

我第一次使用swift尝试使用CommonCrypto(在https://github.com/sergejp/CommonCrypto的帮助下)。这是我的代码:

UnsafeRawPointer(ivData!.withUnsafeBytes
{(pointer) -> UnsafePointer<Any> in
    let ivBuffer = pointer
})

错误是:

  

无法转换类型&#39; UnsafePointer&#39;的值预期的论点   输入&#39; UnsafePointer&lt; _&gt;&#39;

<_>表示什么?我需要做什么?感谢。

2 个答案:

答案 0 :(得分:4)

它正在抱怨pointer。你需要施展它。这是一个示例用法,是创建MD5哈希的一部分:

    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)
    }

答案 1 :(得分:0)

我需要在我的上下文中执行此操作

select value,time from sensor_value where time > '2017-05-21 04:47:48' and deviceId=812;