<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><blockquote type="cite" class="">On Sep 19, 2017, at 9:06 PM, Ted Kremenek via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:<br class=""></blockquote><div><blockquote type="cite" class=""><br class="Apple-interchange-newline"><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I am pleased to announce that Swift 4.0 has been officially released:<div class=""><br class=""></div><div class="">&nbsp;&nbsp;<a href="https://swift.org/blog/swift-4-0-released/" class="">https://swift.org/blog/swift-4-0-released/</a></div><div class=""><br class=""></div><div class="">Swift 4 is available in Xcode 9 (which went live on the Mac App Store earlier today) and we will be posting an official toolchain shortly as well (likely early tomorrow morning).</div><div class=""><br class=""></div><div class="">Official builds have been posted for Linux (Ubuntu 16.10, Ubuntu 16.04 and Ubuntu 14.04). &nbsp;For those of you downloading the Linux builds, please note that there is a new signing key (search for 'Swift 4.x Release Signing Key’) on the downloads page:</div><div class=""><br class=""></div><div class="">&nbsp; <a href="https://swift.org/download/" class="">https://swift.org/download/</a></div><div class=""><br class=""></div><div class="">Thank you to everyone who contributed to making this release happen!</div><div class=""><br class=""></div><div class="">Ted</div></div>_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""><div class="">And as a PSA: Data is its own slice type in Swift 4, and Data slices are not copied correctly when COW is invoked on them (see: SR-5810). The workaround, for now, is to cast any Data for which you want to make a mutable copy to NSData and back. So, rather than this:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal;" class="">func doSomething(with data: Data) {</div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var mutableData = data</div><p style="margin: 0px; line-height: normal; min-height: 14px;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><br class="webkit-block-placeholder"></p><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>mutableData.append(0x01)</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>print("modified data: \(mutableData as NSData))")</div><div style="margin: 0px; line-height: normal;" class="">}</div></div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">do this instead:</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class="">func doSomething(with data: Data) {</div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var mutableData = data as NSData as Data</div><p style="margin: 0px; line-height: normal; min-height: 14px;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><br class="webkit-block-placeholder"></p><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>mutableData.append(0x01)</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>print("modified data: \(mutableData as NSData))")</div><div style="margin: 0px; line-height: normal;" class="">}</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">Otherwise, if ‘data’ happens to be a slice, the data you end up with will be corrupt. Also, in certain circumstances, making a mutable copy of a slice and appending to it can cause data to be written past the end of its parent Data’s buffer, which can either make your app crash or corrupt other memory in the program.</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">Be careful!</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">Charles</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div></div></body></html>