Apple’s Swift Programming Language Updates

Apple’s Swift Programming Language Updates

Apple’s Swift programming language is fast becoming a popular choice among developers for its modern features and cleaner code. It’s safer and easier to maintain than Objective C, allowing for more flexibility.

The latest version, Swift 5.5, has various updates that make it even more powerful. These include exclusivity enforcement for debug and release builds, incremental imports, identity key paths, and more.

1. Swift 4.1

Swift is Apple’s general-purpose programming language that’s dethroning Objective-C as the go-to for iOS app development. This three-year-old successor to C++ enables powerful and safe code while allowing you to write fast applications.

Swift 4.1 adds some key improvements to the core language, as well as enhancements to Foundation and Swift Package Manager. It also brings significant progress to the ABI.

Among the core changes, Swift 4.1 enables the compiler to synthesize Equatable and Hashable conformance automatically for certain types – removing boilerplate and reducing complexity. This includes dictionaries and sets, which now automatically conform to Hashable.

Picture background

It also eliminates the need for implementing an array index type with an associated type by making enumeration case arrays allCases conform to Hashable. Additionally, the compiler supports a new attribute, @dynamicMemberLookup, which specifies that a subscript method will be invoked when accessing properties.

2. Swift 5.8

Swift 5.8 marks an important milestone for the language, as it enables piecemeal adoption of upcoming features while still supporting source-incompatibility. This is in line with Apple’s goals for Swift 3 this year to focus on gradually stabilizing the core language and standard library.

Another major change in Swift 5.8 is a refinement to the result builder implementation that improves compile performance, code completion results, and diagnostics. For instance, the compiler now allows developers to employ local computed properties and property wrappers in result builders.

The update also fixes a small but annoying inconsistency when downcasting collections. Previously, Swift would refuse to downcast a collection of class ClassA to an array of a different type that inherits from ClassA in some circumstances. The update expands the protocol-based approach to optionals to address this issue.

3. Swift Embedded

Swift’s scalable language makes it well-suited for desktop and mobile app development. But it also scales to microcontrollers for IoT and other hardware projects. A new Embedded Swift compilation mode turns off some language features to produce standalone binaries suitable for firmware.

Embedded Swift builds on the existing features of the language to bring it to these constrained environments. For example, Embedded Swift supports ARM and RISC-V microcontrollers. It includes the Any type, which can hold values of any type, as a supertype for NSDictionary and NSSet. The language also adds as? and is? dynamic casts to help you use AnyHashable.

And compared to Objective-C, Swift removes legacy conventions, like semicolons at the end of lines and parenthesis around conditional expressions. This makes code easier to read.

4. Swift Server Workgroup

Creating a platform for Swift server applications is going to require work from multiple players. In the past, framework authors had to rely on C libraries to implement essential functionality like parsing HTTP or SSL/TLS.

Thankfully, that will change with the formation of a new group focused on server APIs and libraries. This workgroup will nurture, mature and recommend projects that enable server-side Swift.

One such project is a library that will provide first-class concurrency support for asynchronous code. Currently, developers have to use completion handlers, which can quickly turn into callback hell.

Another important addition is support for Linux. This is critical for many companies that have already invested in their infrastructure and tools and will make it easier to deploy Swift-based services on those platforms.

5. Swift Package Manager

Swift Package Manager is now a first class citizen in Xcode, making it easier for you to manage dependencies on your projects. You can use public libraries from GitHub or other services, or internal tools and frameworks like UIKit.

The language itself has improved with faster build times, and better type checking of generics. It also has a range of C-like operators that support control statements while, if and switch.

Swift 5 brings a new function called isMultiple(of:) that helps you check if an integer is a multiple of another number. The language also supports a new Result type that encapsulates possible return values and errors in one object. The Result type makes your code more understandable and improves readability. The language also includes a range of other features.

6. Foundation

With Swift, Apple provides a strong ecosystem for developers by including standard libraries in macOS, iOS, tvOS, and watchOS. This reduces application size and improves performance. It also eliminates memory leaks, prevents overflow by enforcing exclusive access to objects, and allows users to define their intent with simple three-character keywords such as var and let.

Swift uses the LLVM compiler technology to produce optimized machine code, which gets the most out of modern hardware. Its syntax and standard library are tuned to make code easier to read, write, and understand.

Swift features a powerful standard library, and the Foundation framework—which includes structures and helpers for networking, internationalization, XML, strings, numbers, dates, and coding standards—is an integral part of the platform. The Swift team plans to rewrite Foundation as a native Swift implementation, eliminating conversion costs between Objective-C and Swift and improving performance.

7. Swift Evolution

Swift is a modern programming language built by Apple that uses proven practices like safe programming patterns. It’s open source, and its clean slate and mature Cocoa frameworks give developers the power to reimagine how apps work.

The Swift evolution process allows anyone to propose changes and have them reviewed by the community. If a proposal is accepted, it becomes a feature of an upcoming version of Swift. The status of a proposal can be found on the Swift evolution status page.

Chris Lattner joins John to discuss Swift 5.3’s new concurrency features, the ongoing evolution of the Swift language and API design, and how Swift’s future looks. Plus, he discusses the importance of library design for the overall feel of a programming language.

 

Leave a Comment