Swift3 UInt8 转 Int
2016-11-04 本文已影响496人
ldclll
//接收到Data类型的蓝牙数据
let data = characteristic.value
//将数据转存到[UInt8]数组
let resultByte = (data?.withUnsafeBytes {
[UInt8](UnsafeBufferPointer(start: $0, count: (data?.count)!))
})! as [UInt8]
//以数据长度进行for循环遍历
for i:Int in 0..<data!.count {
//打印对应的UInt8类型数据
print("testByte[\(i)] = \(resultByte[i])")
//将UInt8数据转换为Int类型
let resultData = NSString(format: "%d", resultByte[i]).integerValue
print(resultData)
}