Macs in Chemistry

Insanely Great Science

Swift 3.0 released


The latest version of swift has been released.

Swift 3 is a source-breaking release, largely due to the changes in SE-0005 and SE-0006. These changes not only impact the names of the Standard Library APIs, but also completely change how Objective-C APIs (particularly from Cocoa) import into Swift. Many of the changes are largely mechanical, but they can be numerous in a typical Swift project. To help with moving to Swift 3, Xcode 8.0 contains a code migrator that can automatically handle many of the need source changes. There is also a migration guide available to guide you through many of the changes — especially through the ones that are less mechanical and require more direct scrutiny.

Thus there is better translation of Objective-C APIs into Swift, meaning that code imported from Objective-C and translated into Swift will be more readable and Swift-like. The bad news is any code previously imported from Objective-C into Swift will not work in Swift 3; it will need to be re-imported.

There was also a blog post describing how to work with JSON in swift, this is particularly important if your app communicates with a web application, information returned from the server is more often than not formatted as JSON.

import Foundation

let data: Data // received from a network request, for example
let json = try? JSONSerialization.jsonObject(with: data, options: [])

blog comments powered by Disqus