gpt4 book ai didi

Swift - 无法将类型 'UnsafePointer' 的值转换为预期的参数类型 'UnsafePointer<_>'

转载 作者:搜寻专家 更新时间:2023-11-01 06:01:49 24 4
gpt4 key购买 nike

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

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

错误是:

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

<_> 是什么意思?表示?我需要做什么?谢谢。

最佳答案

它提示的是指针。你需要施放它。这是一个示例用法,是创建 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)
}

关于Swift - 无法将类型 'UnsafePointer<Any>' 的值转换为预期的参数类型 'UnsafePointer<_>',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47641491/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com