I've seen some strange gymnastics involving MemoryLayout and arrays when people want to add a plain old byte to a Data/NSData. What is the current accepted practice? Can I not just so something like this?
var myData = Data()
let value: UInt8 = 5
myData.append( value)
Yes you can. Your syntax is correct and valid.
Data conforms to MutableCollection, it can be treated as an array of UInt8 values and it's pretty easily convertible from and to [UInt8].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With