Search code examples
iosswiftswift3nsdata

BindMemory migration Swfit 3


How to migrate this code to Swift 3?

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

I'm getting below error

'bytes' is unavailable: use withUnsafeBytes instead


Solution

  • keyData is type of Data object and that doesn't have property bytes, convert keyData to NSData and then access bytes.

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