Mik*_*mac 5 crc32 zlib swift xcode9
我是 swift/xcode 的新手,我正在尝试使用 crc32 函数,正如这里提到的,它是在 libz.dylib 的 zlib 中提供的。
我已经修改了代码,以便我现在尝试:
let message1 = "some message".first?.value!.data(using: String.Encoding.utf8, allowLossyConversion: false)
let crc = crc32(CLong(0), UnsafePointer<Bytef>(strcat!.bytes), UInt(message1!.length))
但是我遇到了错误:use of unresolved identifier 'crc32'。
谁能帮我弄清楚在尝试使用 crc32 函数时我可能会遗漏哪一步?
谢谢!
在 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))")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4642 次 |
| 最近记录: |