Data Value Changing in Swift Playground

Viewed 181

In a playground, the following code initializes Data using an UnsafeBufferPointer, as described in the Apple Foundation Documentation

let data = Data()
let test = Array(0..<10)
let pointer = UnsafeRawPointer(test).assumingMemoryBound(to: UInt8.self)
data = Data.init(buffer: UnsafeBufferPointer(start: pointer, count: MemoryLayout.size(ofValue: test)))
data[8]

Running this program multiple times produces different values for data[8]. Why is the value changing?

1 Answers
Related