On This Page

Version Compatibility

This book describes Swift 4.2, the default version of Swift that’s included in Xcode 10.0. You can use Xcode 10.0 to build targets that are written in either Swift 4 or Swift 3.

Note

When the Swift 4.2 compiler is working with Swift 3 code, it identifies its language version as 3.4. As a result, you can use conditional compilation blocks like #if swift(>=3.4) to write code that’s compatible with multiple versions of the Swift compiler.

When you use Xcode 9.2 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 in Swift 3, and vice versa. This means, if you have a large project that’s divided into multiple frameworks, you can migrate your code from Swift 3 to Swift 4 one framework at a time.

About Swift

A Swift Tour

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software