May The 4th Be Swift You

Got your Swift 3 rewrites all done? Good, good, because now it’s time for…

What’s new in Swift 4.0

Swift 4.0 is a major new release for everyone’s favorite app development language, and introduces a variety of features that let us write simpler, safer code. You’ll be pleased to know it’s nothing as dramatic as the epic changes introduced with Swift 3.0, and indeed most changes are fully backwards-compatible with your existing Swift code. So, while you might need to make a handful of changes it shouldn’t take long.

WARNING: Swift 4 is still under active development. I’ve selected some of the most interesting and useful new features for discussion below, all of which are implemented and available to try now. Please keep in mind that more features are likely ship in the months before final release.

  • Swifty encoding and decoding…
  • Multi-line string literals…
  • Improved keypaths for key-value coding…
  • Improved dictionary functionality…
  • Strings are collections again!…
  • One-sided ranges…
  • There’s more still to come…

The first release of Xcode that ships with Swift 4 is likely to arrive in June, presumably along with iOS 11, tvOS 11, watchOS 4, and macOS Somewhere Else In California. What we’ve seen so far is already promising, particularly because it’s clear the team is working hard to make Swift 4 as additive as possible. Primarily adding new features rather than breaking or modifying existing ones should make it easier to upgrade to, and hopefully signals the start of a new stability for the language…

One feature that was postponed was ABI compatibility, which would allow developers to distribute compiled libraries – one of the few key missing features that remain in Swift today. Hopefully we’ll get it before Swift 5… So if you want to get a jump on this year’s Grand Transition, go check that out.

And if you’re really eager:

Playground: Whatʼs new in Swift 4

I made an Xcode playground that lets you try out many of the new features coming in Swift 4. You can

download it on GitHub


The cool thing is that you can run the playground right now in Xcode 8.3; you donʼt have to wait for the first official Swift 4.0 beta, which will probably come as part of Xcode 9 at WWDC. All you need to do is install the latest Swift snapshot from (donʼt worry, itʼs easy)… Hands-on code examples to help you learn what’s new in Swift 4: new encoding and decoding, smarter keypaths, multi-line strings, and more!

Yeah, personally I think we’ll manage to contain ourselves for that 17 more days, thanks. Handy playground to have around then though!


Breaking changes in Swift 4 What’s New in Swift 4? Encoding and Decoding in Swift 4 Migrating to Swift 4

What’s New in Swift (WWDC 2017.402)

WWDC videos on Swift:

Exploring the new String API in Swift 4Strings in Swift 4Swift Substrings

The surprising awesomeness of Grouped Dictionaries The startling uniquing of Swift 4 dictionaries Functional Lenses: an exploration in Swift

Kuery: “A type-safe Core Data query API using Swift 4’s Smart KeyPaths”

Parsing JSON in Swift 4

Ultimate Guide to JSON Parsing With Swift 4

JSON with Encoder and Encodable

JSON to Swift with Decoder and Decodable

Friday Q&A 2017-07-14: Swift.Codable

Decoding Dictionaries in Swift

Swift 4 Decodable: Beyond The Basics

Swift 4’s Codable: One last battle for Serialization

What’s New in Swift 4 by Example

Key Value Observation in iOS 11

What’s New In Animations In Swift 4 Struct References

DefaultsKit “leverages Swift 4’s powerful Codable capabilities to provide a Simple and Strongly Typed wrapper on top of UserDefaults.”

Why not use UserDefaults to store Codable objects

Swift and KVO context variables

A Funny Thing Happened On The Way To This Array

Friday Q&A 2017-08-11: Swift.Unmanaged

The Best New Features in Swift 4

Floating-point Swift, ulp, and epsilon

Weak Arrays

Understanding Swift 4 generics and applying them in your code

#318: Codable Enums ?Swift Tip: Codable Enums

Better initializers and defaulted arguments

First-Class Swift API for Objective-C Frameworks

The surprising awesomeness of Grouped Dictionaries

Taking Advantage of Generics and Codable in Swift

Eliminating Impossible States with Never

How Swift keypaths let us write more natural code

Alex | May 18, 2017

Leave a Reply