[swift-users] Swift 4.0 released!
Charles Srstka
cocoadev at charlessoft.com
Tue Sep 19 22:05:36 CDT 2017
> On Sep 19, 2017, at 9:06 PM, Ted Kremenek via swift-users <swift-users at swift.org> wrote:
>
> I am pleased to announce that Swift 4.0 has been officially released:
>
> https://swift.org/blog/swift-4-0-released/ <https://swift.org/blog/swift-4-0-released/>
>
> 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).
>
> Official builds have been posted for Linux (Ubuntu 16.10, Ubuntu 16.04 and Ubuntu 14.04). 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:
>
> https://swift.org/download/ <https://swift.org/download/>
>
> Thank you to everyone who contributed to making this release happen!
>
> Ted
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
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:
func doSomething(with data: Data) {
var mutableData = data
mutableData.append(0x01)
print("modified data: \(mutableData as NSData))")
}
do this instead:
func doSomething(with data: Data) {
var mutableData = data as NSData as Data
mutableData.append(0x01)
print("modified data: \(mutableData as NSData))")
}
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.
Be careful!
Charles
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170919/39a70e71/attachment.html>
More information about the swift-users
mailing list