我尝试将 UInt8 数组转换为显式值,但我尝试了多种方式,但无法获得我能理解的值。我该怎么做才能获得明确的价值?
我的 UInt8 数组:
[216, 61, 233, 124, 240, 144, 66, 244]
我的代码:
guard let characteristicData = characteristic.value else { return "Error" }
let count = (characteristicData.count) / MemoryLayout<UInt8>.size
var array = [UInt8](repeating: 0, count: count)
characteristicData.copyBytes(to: &array, count:count * MemoryLayout<UInt8>.size)
let characters = array.map { Character(UnicodeScalar($0)) }
let result = String(Array(characters))
print(array)
print(result.utf8)
我的输出:
Ø=é|ðBô