1

Swift 4 code:

self.dataArray = data.withUnsafeBytes {
                    [UInt16](UnsafeBufferPointer(start: $0, count: data.count))
                }

From looking at other answers to similar problems, I changed the above to:

self.dataArray = data.withUnsafeBytes {$0.load(as: [UInt16].self)}

The code compiles but gives me an exception: EXC_BAD_ACCESS (code=EXC_I386_GPFLT)

Any ideas? Thanks

RJG
  • 21
  • 2
  • 1
    This is probably what you are looking for: [Converting Swift Data into Int16](https://stackoverflow.com/a/45150010/1187415). – Martin R Feb 07 '20 at 19:08

1 Answers1

0

Thanks to Martin R. The answer to my problem was:

data.withUnsafeBytes{ Array($0.bindMemory(to: UInt16.self))}
RJG
  • 21
  • 2