Here is my Swift 2 code to extract a ble charcteristic value:
var ts:UInt16 = 0
var tsData = characteristic.value
print(" timeStamp value: \(characteristic.value)")
let count = tsData!.length / sizeof(UInt32)
var array = [UInt32](count: count, repeatedValue: 0)
tsData!.getBytes(&array, length: count * sizeof(UInt32))
// Swap each integer:
for i in 0 ..< count {
array[i] = array[i].byteSwapped
}
let timestampHex = NSData(bytes: &array, length: count*sizeof(UInt32))
print(" timestampHex value: \(timestampHex)")
Notification received:
timeStamp value: Optional(<31000000>)
timestampHex value: <00000031>
I need to convert the timestampHex value to an Int (or UInt). The example above should then have an Int of 49.
I am using XCode 7 Swift 2.
Any help in accomplishing this would appreciated, thanks...