0

The following piece of code takes a given NSData and "fills" it into a struct of type Container.

data: NSData ....
var tempBuffer: Container? = nil
data.getBytes(&tempBuffer, length: MemoryLayout<Container>.size)

How do I formulate this using Data instead of NSData? I simply do not understand how to formulate it in Swift. I guess you need withUnsafeBytes...

Thanks Chris

Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
Chris
  • 1,231
  • 2
  • 10
  • 20
  • It's recommended to use the native `Data` API `withUnsafeBytes`. Please see https://stackoverflow.com/questions/38023838/round-trip-swift-number-types-to-from-data – vadian Feb 09 '18 at 10:56

1 Answers1

0

Since Data is convertible to NSData, you can use as:

let nsData = data as NSData
Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223