Guides and Sample Code


The Swift Programming Language (Swift 4)


Version Compatibility

This book describes Swift 4.0, which is the default version of Swift included in Xcode 9. You can use Xcode 9 to build targets that are written in either Swift 4 or Swift 3.

When you use Xcode 9 to build Swift 3 code, most of the new Swift 4 functionality is available. That said, the following features are available only to Swift 4 code:

  • Substring operations return an instance of the Substring type, instead of String.

  • The @objc attribute is implicitly added in fewer places.

  • Extensions to a type in the same file can access that type’s private members.

A target written in Swift 4 can depend on a target that’s written using Swift 3, and vice versa. This means, if you have a large project that is divided into multiple frameworks, you can migrate your code from Swift 3 to Swift 4 one framework at a time.