I got this code here from an app I am working on. I inherited this code when the BLE guy left the team. I am not good with low level stuff and Data stuff. I am UI/UX front end person, and now I do need to get my hands dirty. This code is now a bit old and using deprecated code. I have unsuccessfully been trying to silence the warning, but I keep ending up with he same code or with errors.
This is the code that generates the warning. On the return line when using withUnsafeBytes
extension Data {
func scanValueFromData<T>(start: Int = 0, invalid: T) -> (T, Int) {
let length = MemoryLayout<T>.size
guard self.count >= start + length else {
return (invalid, start+length)
}
return (self.subdata(in: start..<start+length).withUnsafeBytes{ $0.pointee }, start+length)
}
}
This method is used to decode a byte array to a struct. I get the data from a BLE service and the various vars are packed into an array of bytes.
If any one as a fix for this or a better way to do id.