May 08

Interesting.

func doStuff(arr: Array) {
    var value: UInt8!// = 0
    let data = NSData(bytes: arr, length: arr.count * sizeof(UInt8))
    data.getBytes(&value, range: NSMakeRange(0, 1))
    println(value)
}

let arr: [UInt8] = [ 0x00, 0x34, 0x56, 0xFF ]
doStuff(arr)

value will be nil if 0x00 is read from NSData. In case value is not declared as Optional, 0 is read instead. Just something to keep in mind.

preload preload preload