Swift code didUpdateValueFor characteristic

I have the following code in my app, which reads a single byte send from a peripheral. I now want to read 20 bytes sent together from the peripheral. How do I change the swift code?

func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
Code Block
var u16: UInt8

u16 = UInt8((characteristic.value! as NSData).bytes.bindMemory(to: Int.self, capacity: characteristic.value!.count).pointee)// get input ascii value //

let chart = Character(UnicodeScalar(u16))// make into a character //
Your code is sort of a mess (an example of bad usage of bytes) and can be simplified as:
Code Block
func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
let u16 = characteristic.value![0]
let chart = Character(UnicodeScalar(u16))// make into a character //
}

(And you should better avoid naming u16 for a variable of type UInt8.)


So, where is your 20 bytes placed? Next to the first byte (u16)? Or some where else?
One more, what the 20 bytes are representing? 10 sixteen-bit integers? Or a text containing maximum-20 ascii characters? Or something else?
Swift code didUpdateValueFor characteristic
 
 
Q