title: Swift Data to Int array
body: <p>I'd like to access the raw bytes in Data as an array of numeric types for quick parsing.  I have lots of data to parse, so I'm looking for efficiency.  Data is a mix of shorts, ints, longs, and doubles.</p>
  <p>The below code seems to work and be fast, but I'm getting deprecated warning: 'withUnsafeBytes' is deprecated</p>
  <p>I can't figure out the updated way to treat the underlying bytes as an array of numbers for quick lookup.</p>
  <pre><code>    var data: Data = ...
              
      // create &quot;virtual&quot; arrays of different types to directly access bytes (without copying bytes)
      
      let ushortArray: [UInt16] = data.withUnsafeBytes {
          [UInt16](UnsafeBufferPointer(start: $0, count: data.count/2))
      }
      let intArray: [Int32] = data.withUnsafeBytes {
          [Int32](UnsafeBufferPointer(start: $0, count: data.count/4))
      }
  
      // Access data simply
      var i1: UInt16 = ushortArray[0]
      var i2: Int32 = intArray[1]
  </code></pre>
  <p>P.S. I'm not concerned with big/little endian</p>