I've found what I believe is a bug. Though I'm unclear if the bug is in Swift 3.1 or Swift 3.2/4.0. All I can say for sure is the behavior is quite drastically different between the two.
For the code below (and attached): import Cocoa var data = Data(bytes: [0x50, 0x4B, 0x01, 0x02, 0x41, 0x61]) data.removeFirst(4) let base64 = data.base64EncodedString() let str = String(bytes: data[0..<2], encoding: .utf8)! print("Base64: \(base64), String: \(str)") If I compile and run that with the Swift included in Xcode 8.3.3 (e.g., swift ./data-bug.swift) it outputs: Base64: QWE=, String: Aa. Which is what I expect. With the Swift that is included with Xcode 9.0 beta 6 (9M214v) (e.g., swift -swift-version 3 ./data-bug.swift). It performs an illegal hardware instruction and crashes. It also does this if I use use the version 4 of the compiler. Is this a bug? If so where is the bug? Was this always meant to not work and Swift 3.1 just happened to work or is there now an issue in the Swift 3.2 implementation?
data-bug.swift
Description: Binary data
_______________________________________________ swift-corelibs-dev mailing list swift-corelibs-dev@swift.org https://lists.swift.org/mailman/listinfo/swift-corelibs-dev