0

I am seeing a deprecation warning from xcode for using withUnsafeBytes. Below is the code snippet. Can anyone suggest the right way to use withUnsafeBytes without throwing the warning : withUnsafeBytes' is deprecated: use withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R instead. I have tried few other links and solutions but nothing seems to be working.

var keyBytes = data.withUnsafeBytes {
            [UInt8](UnsafeBufferPointer(start: $0, count: data.count))
}
Max
  • 5,380
  • 6
  • 42
  • 66
  • If your intent is only convert `Data` to array of bytes all you need is `let bytes = Array(data)`. Note that `Data` conforms to `MutableCollection`, `RandomAccessCollection` and `RangeReplaceableCollection` since Swift 3 – Leo Dabus Jan 04 '21 at 18:19
  • Array(data) did work thanks – Max Jan 05 '21 at 17:04

0 Answers0