Swift 4 is now available! Swift 4 builds on Swift 3 with more robustness and stability, provides source compatibility for Swift 3, improves the standard library, and adds archiving and serialization features.
You can get a quick overview of Swift 4 features by viewing WWDC 2017: What’s New in Swift or the full release notes.
First, language update
String
Swift 4 includes a faster, easier to use String implementation that preserves Unicode correctness and adds support for creating, using, and managing substrings.
Details:
-
SE-0163 String Revision: Collection Conformance, C Interop, Transcoding
-
SE-0168 Multi-Line String Literals
-
SE-0178 Add unicodeScalars property to Character
-
SE-0180 String Index Overhaul
-
SE-0182 String Newline Escaping
-
SE-0183 Substring performance affordances
A collection of
Swift 4 improves the creation, use, and management of collection types.
Details:
-
SE-0148 Generic Subscripts
-
SE-0154 Provide Custom Collections for Dictionary Keys and Values
-
SE-0165 Dictionary & Set Enhancements
-
SE-0172 One-sided Ranges
-
SE-0173 Add
MutableCollection.swapAt(_:_:)
Archiving and serialization
Swift 4 supports archiving of structured and enumerated types, and type-safe serialization of external formats such as JSON and PList.
Details:
-
SE-0166 Swift Archival & Serialization
other
-
SE-0104 Protocol-oriented integers
-
SE-0142 Permit where clauses to constrain associated types
-
SE-0156 Class and Subtype existentials
-
SE-0160 Limiting @objc inference
-
SE-0164 Remove final support in protocol extensions
-
SE-0169 Improve Interaction Between private Declarations and Extensions
-
SE-0170 NSNumber bridging and Numeric types
-
SE-0171 Reduce with inout
-
SE-0176 Enforce Exclusive Access to Memory
-
SE-0179 Swift run Command
Two, the new compatible mode
When Swift 4 is released, you may not need to change the code to use the new version of the compiler. The compiler supports two language modes:
-
Swift 3.2: In this mode, the compiler will accept most source code built using the Swift 3.x compiler. To provide this level of source compatibility, updates to preexisting apis that are part of the standard library or API provided by Apple will not appear in this pattern. Most of the new language features in Swift 4 are provided in this language pattern.
-
Swift 4.0: This mode covers all Swift 4.0 language and API changes, and some projects may require source migration.
The language mode is specified by -swift-version to the compiler and is handled automatically by swift package manager and Xcode.
Details:
-
Migrating to Swift 4
Upgrade package manager
Swift 4 introduces new workflow capabilities and a more complete API for Swift Package Manager:
-
It’s easy to develop multiple packages, or work together on branches of multiple packages, before tagging your first official release.
-
Optionally control the packages published to users.
-
The new Package API allows packages to specify some new Settings, giving authors more control over how packages are built and how source code is organized on disk. Overall, the API for creating packages is now clearer, while preserving source compatibility with older packages.
-
On macOS, Swift packages are now built in a sandbox that prevents network access and file system modification, helping to mitigate the impact of malicious programs.
Details:
-
SE-0146 Package Manager Product Definitions
-
SE-0149 Package Manager Support for Top of Tree development
-
SE-0150 Package Manager Support for branches
-
SE-0158 Package Manager Manifest API Redesign
-
SE-0162 Package Manager Custom Target Layouts
-
SE-0175 Package Manager Revised Dependency Resolution
-
SE-0179 Swift run Command
-
SE-0181 Package Manager C/C++ Language Standard Support
4. Relevant address
The document
-
Swift 4.0 documentation has been updated on the official website and is available as a free download on Apple’s iBooks store.
download
-
swift.org/download/