Search code examples
iosswift3uint8array

Swift 3.0 convert Data to Array<UInt8>


How to convert Data to array of UInt8?

func serialPort(_ serialPort: ORSSerialPort, didReceive data: Data) {
print("recieved:\(data)")
let arr: [UInt8] = Data(???)???
}

log recieved:70 bytes


Solution

  • Got it!

    var recived = [UInt8]()
    
    func serialPort(_ serialPort: ORSSerialPort, didReceive data: Data) {
            recived.removeAll()
            print("recieved:\(data))")
            recived.append(contentsOf: data)
    }