<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Not sure on exactly how you are wanting to use this but you could approach this like:<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(39, 42, 216);" class=""><span style="color: #ba2da2" class="">let</span><span style="color: #000000" class=""> bytes: [</span><span style="color: #703daa" class="">UInt8</span><span style="color: #000000" class="">] = [ </span>0xC0<span style="color: #000000" class="">, </span>0xC0<span style="color: #000000" class="">, </span>0xA1<span style="color: #000000" class="">, </span>0x00<span style="color: #000000" class="">, </span>0xC0<span style="color: #000000" class="">, </span>0xC0<span style="color: #000000" class="">, </span>0xA1<span style="color: #000000" class="">, </span>0x00<span style="color: #000000" class="">]</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="color: #ba2da2" class="">let</span> slice = <span style="color: #4f8187" class="">bytes</span>[<span style="color: #272ad8" class="">0</span>..&lt;<span style="color: #272ad8" class="">4</span>]</div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129);" class=""><span style="color: #4f8187" class="">slice</span><span style="color: #000000" class="">.</span>withUnsafeBytes<span style="color: #000000" class=""> { buffer </span><span style="color: #ba2da2" class="">in</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="color: #ba2da2" class="">let</span> d = <span style="color: #703daa" class="">Data</span>(bytesNoCopy: <span style="color: #703daa" class="">UnsafeMutableRawPointer</span>(mutating: buffer.<span style="color: #703daa" class="">baseAddress</span>!), count: buffer.<span style="color: #703daa" class="">count</span>, deallocator: .<span style="color: #3e1e81" class="">none</span>)</div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="color: #000000" class="">&nbsp; &nbsp; </span>// whatever you do, dont let d escape</div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div><br class=""><blockquote type="cite" class=""><div class="">On May 4, 2017, at 16:31, Rick Mann via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Is it possible to make a (immutable) Data() object from a slice of a [UInt8] and avoid copying the data?<br class=""><br class="">-- <br class="">Rick Mann<br class=""><a href="mailto:rmann@latencyzero.com" class="">rmann@latencyzero.com</a><br class=""><br class=""><br class="">_______________________________________________<br class="">swift-users mailing list<br class="">swift-users@swift.org<br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></div></blockquote></div><br class=""></div></body></html>