BindMemory迁移Swfit 3

时间:2016-10-05 09:54:50

标签: ios swift swift3 nsdata

如何将此代码迁移到Swift 3?

let keyBytes = keyData.bytes.bindMemory(to: Void.self, capacity: keyData.count)

我收到以下错误

  

'bytes'不可用:改为使用withUnsafeBytes

1 个答案:

答案 0 :(得分:2)

keyDataData对象的类型,没有属性bytes,将keyData转换为NSData,然后访问bytes

let keyBytes = NSData(data: keyData).bytes.bindMemory(to: Void.self, capacity: keyData.count)