Top Picks from WWDC 2017

By Alex Robinson on 10 Jun 2017
  • iOS
  • Featured

Much of Apple’s Keynote was focused on hardware updates including a new iPad Pro, MacBook and MacBook Pro updates, iMac updates and the new HomePod speaker. There was even a preview of the iMac Pro and support for VR on macOS.

While the hardware updates were great, the focus of the conference was really about the new technology kits like ARKit and Core ML as well as a number of improvements to the existing developer tools. Here are our top picks from the event.

Swift 4

Swift 4

Swift is open now so there weren’t any real surprises here, but there are a number of improvements that will make developers more productive. For most projects migrating from Swift 3 to Swift 4 should be fairly painless. Better yet, Swift 3.2 and Swift 4 targets can coexist and link together.

Multi-line Strings

Triple quotes can be used for multi-line string literals.

let jsonString = """
        [{
        "name": "K9",
        "manufacture_date": "5112-04-23T18:25:43.511Z",
        "is_cybermen": false,
        "home_planet": "Earth"
        }, {
        "name": "Dalek Sec",
        "manufacture_date": "1993-04-23T18:25:43.511Z",
        "is_cybermen": false,
        "home_planet": "Skaro"
        }]
    """

Codable

JSON parsing has never been trivial in Swift which has resulted in a large number of third party libraries to try and make it easier. Swift 4 now provides support for encoding and decoding both classes and value types to/from JSON (as well as PLists) with the new Codable protocol. In most cases adding Codable is all that is required, but it is possible to provide custom key mappings and decoding strategies.

struct Robot: Codable {
    let name: String
    let manufactureDate: Date
    let isDalek: Bool
    let homePlanet: String
}

let data = jsonString.data(using: .utf8)!
let decoder = JSONDecoder()
if let robots = try? decoder.decode([Robot].self,
                                    from: data) {
    robots.forEach { robot in
        print("\(robot.name) is from \(robot.homePlanet)")
    })
}

Keypaths and KVO

Keypaths in Objective-C is a powerful feature for accessing properties of an object and an essential component of Key Value Observing, but they are defined as strings making keypaths error prone and keypaths did not support Swift value types. In Swift 4 there is a new keypath literal making keypaths both type safe and fast.

let homePlanetKeyPath = \Robot.homePlanet

let homePlanet = robot[keyPath: homePlanetKeyPath]

Key Value Observing replaces the ugly observeValueForKeyPath with a new block-based syntax making it much easier to implement and eliminates the need to explicitly remove observers in a deinit method.

let observation = robot.observe(\.homePlanet) { ... }

Strings

It seems like every update to Swift also includes major changes to Strings. Strings are a foundational type and important to get right. In Swift 4, Strings are collections again simplifying a number of string related tasks.

let quote = "Never ignore coincidence. Unless, of course, you’re busy. In which case, always ignore coincidence."

print("Number of characters: \(quote.count)")

quote.reversed()

Related WWDC Sessions:


Drag and Drop

Drag and Drop for iPad

The iPad multitasking feature received a major overall with the introduction of Drag and Drop support between apps making the iPad even more useful as a productivity tool. The basics of Drag and Drop seem straight forward to implement with many UIKit components having native support, but the system is still very flexible. WWDC devoted a lot of time to Drag and Drop suggesting this will be an important feature for both stock and third party apps.

Related WWDC Sessions:


Xcode 9

Xcode 9

Xcode received a number of nice improvements that will make developers more productive including a completely rewritten source code editor.

Refactoring in Swift

Not only is the new source editor faster and more reliable, but Xcode now supports automated refactoring for Swift code. For Swift developers, this has been one of the most requested improvements since Swift was introduced. Even better, Xcode’s local transformation engine that enables the refactoring support will be open source as part of the Clang compiler project.

Debugging

The Xcode debugger also received some nice improvements including support for wireless debugging on iOS and tvOS as well as multiple simulator instances making testing faster.

Testng

Async testing is nothing new for XCUnit, but the new API with the XCTWaiter class makes it more explicit.


// Explicit about which expectations to wait on
wait(for: [documentExpectation], timeout: 10)

// Waiter instance delegates to test 
XCTWaiter(delegate: self).wait(for: [documentExpectation], timeout: 10)

// Waiter class returns result 
let result = XCTWaiter.wait(for: [documentExpectation], timeout: 10) 
if result == .timedOut { 
    // handling the timeout...
}

UITests received new support for attachments for things like files, binary data, and screenshots that can be captured during tests. Being able to capture a screenshot leading up to a failed test can be handy for trouble shooting. Additionally, this feature could also be great for automating the capture of app screenshots especially for apps that support multiple languages.

Named colors support in Asset Catalogs

One of my favorite new features in Xcode is the support for named colors in the asset catalog. The named colors are available in both code and in interface builder making much easier to manage and update colors across an app.

headerView.backgroundColor = UIColor(named:"header-background")

Auto Layout and Scrollviews

Every year Auto Layout gets a little better and this year is no exception. Two of the biggest remaining pain points of Auto Layout have been addressed in iOS 11.

Using Auto Layout with Scrollviews was always challenging because the Scrollview had to deal with the size of its frame and the size of the content within the Scrollview making the size ambiguous for Auto Layout. iOS 11 adds the contentLayoutGuide and frameLayoutGuide to remove the ambiguity.

The second common pain point with Auto Layout is dynamic cell height in table views. By default cell height will be dynamic by default in table views in iOS 11.

Dynamic Type with Custom Fonts

Dynamic Type was introduced in iOS 7 with fonts defined in terms of text styles instead of point sizes. This allowed the font size and weight to be adjusted based on user preferences, but it has been limited to only the system font until now. This allows apps to adopt font types that compliment their theme without dropping support for the standard text styles making easier to theme apps both in code and Interface Builder.

let bodyMetrics = UIFontMetrics(forTextStyle: .body)
let customFont = ... // your custom font
let font = bodyMetrics.scaledFont(for: standardFont)

These are just a few of the many improvements in Xcode 9. Check out the related sessions for more.

Related WWDC Sessions:


ARKit

ARKit

While we knew Apple was researching augmented reality, we didn’t really expect to see any support for AR in iOS 11. ARKit gives developers the ability to add augmented reality features like Pokemon GO to their own apps. IKEA has already announced plans to use ARKit for visualizing furniture in your home.

It will be exciting to see what apps will do with ARKit.

Related WWDC Sessions:


CoreML

Core ML

Similar to Tensor Flow Lite introduced at Google I/O earlier this year, Apple introduced Core ML and computer vision for running machine learning models on device. Core ML can be used for things such as live text detection, barcode, object tracking, face detection and much more making apps smarter and more context aware. One example given is the ability to identify the type of flower in a photo or track features of a face on the camera. Having this run on device also means those images can stay on device rather than going up to a cloud.

Related WWDC Sessions:

WWDC 2017 introduced a lot of new technologies in the AI space as well as many improvements that will make developers happy. There are dozens of sessions to watch covering a number of topics but these were some of our top picks from this year.

Join Our Newsletter

Stay up to date with the latest mobile app dev news, technologies and events with Atomic Robot.