我正在尝试修复此代码。目前,我收到此错误。
下标'subscript(_ :)'要求'UInt8.Bound'符合'FixedWidthInteger'
和
下标'subscript(_ :)'要求'UInt8'符合'RangeExpression'
不确定在此情况下错误是什么意思。
let v = characteristic.value;
let count = (v?.count)! / MemoryLayout<UInt8>.size
var array = [UInt8](repeating: 0, count: count)
v?.copyBytes(to: &array, count:count * MemoryLayout<UInt8>.size)
let numCharacteristics = (v![0] & 0xf0) >> 4
let numDataPoints = v![0] & 0x0f
for index in 0..<numDataPoints-1 {
datapoint = v![index] + (v![index+1] << 8)
datapointArray.append(datapoint!)
}
答案 0 :(得分:0)
Data
类型不能用UInt8
下标。试试:
for index in 0..<numDataPoints-1 {
let intIndex = Int(index)
let datapoint = v![intIndex] + (v![intIndex+1] << 8)
datapointArray.append(datapoint)
}