There were a lot of new services announced at Apple’s press event at its California HQ, including the launch of Apple Card, a paid-for News+ service and a new premium TV offering, to name a few. Find out more about the announcements here.
However, these services were not the only things Apple unveiled. Ted Kremenek, manager of the languages and runtimes team at Apple, announced the release of Swift 5, which represents a major milestone in the evolution of this language.
Swift 5 highlights
As Kremenek noted in the blog post, “thanks to ABI stability, the Swift runtime is now included in current and future versions of Apple’s platform operating systems: macOS, iOS, tvOS, and watchOS. Swift 5 also introduces new capabilities that are building blocks for future versions, including a reimplementation of String, enforcement of exclusive access to memory during runtime, new data types, and support for dynamically callable types.”
If you’d like to give some of the features a try, check out this playground created by Paul Hudson.
Language updates
As mentioned above, the ABI is now stable for Swift 5 on Apple platforms, which means the Swift libraries are incorporated into every macOS, iOS, tvOS, and watchOS release going forward. In short, thanks to ABI stability, users will be able to build apps easier; plus, they will also be smaller since there’s no reason to include those libraries.
There are a bunch of new features in the standard library in Swift 5, such as
- String reimplemented with UTF-8 encoding which can often result in faster code
- Improved support for raw text in string literals
- Result and SIMD vector types added to the Standard Library
- Enhancements to String interpolation, adding more flexibility to construct text from data
- Performance improvements to Dictionary and Set
The latest release implements the following Standard Library proposals from the Swift Evolution process
- SE-0200 Enhancing String Literals Delimiters to Support Raw Text
- SE-0211 Add Unicode Properties to Unicode.Scalar
- SE-0214 Renaming the DictionaryLiteral type to KeyValuePairs
- SE-0215 Conform Never to Equatable and Hashable
- SE-0218 Introduce compactMapValues to Dictionary
- SE-0221 Character Properties
- SE-0225 Adding isMultiple to BinaryInteger
- SE-0228 Fix ExpressibleByStringInterpolation
- SE-0229 SIMD Vectors
- SE-0232 Remove Some Customization Points from the Standard Library’s Collection Hierarchy
- SE-0233 Make Numeric Refine a new AdditiveArithmetic Protocol
- SE-0234 Remove Sequence.SubSequence
- SE-0235 Add Result to the Standard Library
- SE-0237 Introduce withContiguous{Mutable}StorageIfAvailable methods
- SE-0239 Add Codable conformance to Range types
- SE-0241 Deprecate String Index Encoded Offsets
Furthermore, Swift 5 defaults to enforcing exclusive access to memory for both debug and release builds. It also supports dynamically callable types that help improve interoperability with dynamic languages such as Python, JavaScript and Ruby.
The following language proposals from the Swift Evolution process are implemented in Swift 5
- SE-0192 Handling Future Enum Cases
- SE-0213 Literal initialization via coercion
- SE-0216 Introduce user-defined dynamically “callable” types
- SE-0224 Support ‘less than’ operator in compilation conditions
- SE-0227 Identity key path
- SE-0230 Flatten nested optionals resulting from ‘try?’
Package manager updates
There are a bunch of new features in Swift Package Manager, such as dependency mirroring, target-specific build settings, customized deployment targets, and the ability to generate code coverage data, to name a few.
Swift Package Manager includes a number of new features in Swift 5, including dependency mirroring, target-specific build settings, customized deployment targets, and the ability to generate code coverage data. What’s more, the swift run
command now includes the ability to import libraries in a REPL without needing to build an executable.
Swift 5 implements three Package Manager proposals from the Swift Evolution process, namely
- SE-0219 Package Manager Dependency Mirroring
- SE-0236 Package Manager Platform Deployment Settings
- SE-0238 Package Manager Target Specific Build Settings
Migration
The latest version is source compatible with Swift 4, Swift 4.1 and Swift 4.2. To make things easier, Apple’s Xcode 10.2 contains a code migrator that can automatically handle many of the needed source changes. There’s also a migration guide available to guide you through many of the changes.
Last but not least, you’ll find the updated version of The Swift Programming Language for Swift 5 on Swift.org, as well as on the Apple Books store (for free!).
The post What’s new in Swift 5 appeared first on JAXenter.
Source : JAXenter