This code used to be fine (in the sense that the compiler didn't complain):
extension OutputStream {
func write(_ data: Data) -> Int {
return data.withUnsafeBytes { pointer in
return self.write(pointer, maxLength: data.count)
}
}
}
Since Swift 5.0, this produces a warning:
Warning: 'withUnsafeBytes' is deprecated: use
withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R
instead
I tried using the proposed method but I can't seem to wrangle the UnsafeRawBufferPointer
into the UnsafePointer<UInt8>
that OutputStream.write
ultimately requires.
How can I write this function in a non-deprecated way?