Reputation: 71
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)
Upvotes: 4
Views: 2768
Reputation: 285220
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]
.
Upvotes: 4