title: How to convert Objective-C NSData to Swift Data?
body: <p>I have a NSData in Objective-C, the NSData has value <code>0x10</code>, code like bellows:</p>
  <pre><code>@implementation BufUtil
  + (NSData *_Nonnull) getOCBuf {
      std::vector&lt;uint8_t&gt; sendData = {0x10};
      NSData * reqBuf = [[NSData alloc] initWithBytesNoCopy:sendData.data() length:sendData.size() freeWhenDone:false];
      NSLog(@&quot;getOCBuf, oc NSData reqBuf:%@&quot;, reqBuf);
      return reqBuf;
  }
  @end
  </code></pre>
  <p>Then I use the data in Swift, Swift auto convert <code>Objective-C NSData</code> to <code>Swift Data</code>,  but strange things happen, the value in <code>Swift Data</code> is <code>0x60</code>, code like belows:</p>
  <pre><code>public func getOCBuf() -&gt; Data {
      let data = BufUtil.getOCBuf();
      print(&quot;getOCBuf: swift data: \(data.hexEncodedString())&quot;)
      return data
  }
  </code></pre>
  <p>the log is like:</p>
  <pre><code>getOCBuf, oc NSData reqBuf:{length = 1, bytes = 0x10}
  getOCBuf: swift data: 60
  </code></pre>
  <p>Now I am confused with what happened. Why <code>0x10</code> turn into <code>0x60</code>, the two number not Binary complement.</p>
  <p>Can anybody help me, thanks.</p>
  <p>the code:<br />
  <a href="https://github.com/oncealong/SwiftOcDataConvert" rel="nofollow noreferrer">https://github.com/oncealong/SwiftOcDataConvert</a></p>