There are many sources explaining how to do this in Swift 2 , which I used as a base:
var value: Int = 0
let data: NSData = ...;
data.getBytes(&value, length: sizeof(Int))
Then I updated the syntax / naming due to Swift 3 :
var value: Int = 0
let data: NSData = ...;
data.copyBytes(to: &value, count: MemoryLayout<Int>.size)
However, this does not work. The compiler does not like the type value; he says that it should be UInt8. But I want to Int. Does anyone know how I can achieve this?
source
share