There're a lot of sources explaining how to make it in Swift 2 which I took as a base:
var value: Int = 0
let data: NSData = ...;
data.getBytes(&value, length: sizeof(Int))
Then I updated syntax/naming due to Swift 3:
var value: Int = 0
let data: NSData = ...;
data.copyBytes(to: &value, count: MemoryLayout<Int>.size)
Nevertheless it doesn't work. The compiler doesn't like the type of value
, it says it should be UInt8
. But I want Int
. Anybody knows how can I achieve this?