A Look at Swift 5.0  Features and Functionalities

A Look at Swift 5.0 Features and Functionalities

Swift 5 was completed on March 26. Swift 5 is considered a "milestone" in that Apple guarantees the interfaces' binary compatibility for the first tim

Swift 5 was completed on March 26. Swift 5 is considered a “milestone” in that Apple guarantees the interfaces’ binary compatibility for the first time. The most significant impact in practice is that standard libraries are now installed on Apple devices and no longer have to be supplied with every app. Xcode therefore creates smaller binary files.

In 2014, Apple introduced the Swift programming language at the annual WWDC developer conference. Since then, this language has been extensively expanded and improved. Since the first versions were characterized by instabilities and language changes incompatible with the previous versions, the development of the language has since stabilized. Version 4.2 of Swift was delivered with Xcode 10 in September 2018. This version is backward compatible down to the last detail, and only minimal changes to existing code were necessary.

Swift is a modern, object-oriented programming language that picks up many ideas from other paradigms such as functional programming and programming languages ​​such as Objective-C, Rust, Haskell, Ruby, and Python. Although Swift is a type-safe, compiled language for which the compiler can recognize many errors already in the compilation phase, it has a very elegant and compact syntax that is reminiscent of scripting languages.

Swift 5.0 Features

The central topic in Swift 5 is the Application Binary Interface (ABI), which is now considered stable. With the new ABI, Apple can integrate the Swift runtime and libraries into the future releases of its operating systems. The runtime environment for Swift 5 thus finds its way into macOS, iOS, tvOS, and watchOS. It is no longer necessary to integrate these into the individual apps during development. This is intended to make applications smaller, while at the same time making development more accessible.

The stabilization of the binary interface (ABI) in Swift 5.0 was a big turning point. Since then, it has no longer been necessary to deliver the Swift runtime environment as part of every app. Apple offers them along with the operating system. Conversely, this means that, starting with Swift 5.1, not every new Swift function is available on older operating systems for the first time. This mainly affects the standard library; pure compiler features can also be used on earlier versions. Apparently, Apple could provide iOS 12 with a small update with updated Swift, but that is not expected. Mac developers also have to be patient until macOS Catalina is released. 

The exclusive memory access that Swift 4 introduced for debug builds is now also enabled for release builds by default. This feature allows developers to ensure that variables cannot be addressed by a different name as long as they are changed as an inoutargument or as selfwithin a mutatingmethod. The description of this feature also explains that its implementation forms the basis for future additions to the programming language’s functional scope.

Swift 5.1 offers mechanisms to make binary frameworks forward-compatible. The new compiler argument -enable-library-evolution ensures, among other things, that structs and enums are allowed to grow in a binary-compatible manner. Therefore, it is not necessary to reserve space for possible future fields, as is common in C-Structs. Outside the Apple world, for example, on Linux platforms, the ABI remains open to change.

In line with this, the new keyword somehow allows abstract types to be abstracted in the public API. Until now, this was not possible for protocols with so-called associated types. The associated error message “Protocol ‘Equatable’ can only be used as a generic constraint because it has Self or associated type requirements” should have frustrated some developers. These new “opaque” types also guarantee that the same concrete type is always returned. The caller does not find out exactly what that is.

Property wrapper and more compact code

In the beginning, the property wrappers mentioned are one of the most significant changes to this small update. With them, Swift allows user-defined attributes for the first time. You instruct the compiler to delegate getter and setter calls to a property to a third object.

This provides for thread-local, copy-on-write, or atomic features to be created without the compiler having to offer customized support. Even “lazy” properties that Swift has known since a property wrapper could replace version 1. Developers can chain and parameterize the wrappers. In practice you can significantly reduce the boilerplate or instrumentalize code.

Switch to Swift 5

Swift 5 is source compatible with Swift 4, 4.1, and 4.2. To make it easier to switch the code base of a project to Swift 5, Apple provides a code migrator in Xcode 10.2. When you hire Swift developer, he should be able to automatically perform many of the code changes that are necessary when switching to Swift 5. A guide for the Swift 5 migration is also available.

Among the changes in Swift 5 presented in less detail in the introduction of the language version are a new implementation of strings and the new data type Result. The original application of the strings brings UTF-8 encoding and should lead to faster code. The newly introduced Resultdata type was added to the Swift 5 standard library to solve weaknesses in Swift’s previous error handling. By this, the authors of the now implemented proposal mean sophisticated error handling and not Errorerrors corresponding to the type.

The development of the Swift programming language is under the Apache 2.0 license. Further information can be found in the blog post on the release of the language version in the corresponding repository on GitHub or in the documentation.

COMMENTS

WORDPRESS: 0
DISQUS: 0