如何在 swift (Xcode 9) 中使用 zlib 中的 crc32 [英] How to use crc32 from zlib in swift (Xcode 9)
本文介绍了如何在 swift (Xcode 9) 中使用 zlib 中的 crc32的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 swift/xcode 的新手,我正在尝试使用 crc32 函数,如前所述 这里,是在 libz.dylib 的 zlib 中提供的.
I'm new to swift/xcode and am trying to use the crc32 function that, as mentioned here, is provided in zlib from libz.dylib .
我已经修改了代码,现在正在尝试:
I've modified the code so that I am now trying:
let message1 = "some message".first?.value!.data(using: String.Encoding.utf8, allowLossyConversion: false)let crc = crc32(CLong(0), UnsafePointer
但是我遇到了错误:use of unresolved identifier 'crc32'
.
谁能帮我弄清楚在尝试使用 crc32 函数时我可能遗漏了哪一步?
Could anyone help me to figure out what step I might be missing in trying to use the crc32 function?
谢谢!
推荐答案
在 Swift 5 中:
In Swift 5:
import zlib
let data = Data(base64Encoded: "SGF2ZSBhIG5pY2UgZGF5ISA6KQ==")!
let checksum = data.withUnsafeBytes { crc32(0, $0.bindMemory(to: Bytef.self).baseAddress, uInt(data.count)) }
print("crc32: 0x\(String(format:"%08X", checksum))")
这篇关于如何在 swift (Xcode 9) 中使用 zlib 中的 crc32的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文