5 New Features and Updates in Swift 5 Every Developer Should Know

A new version of Swift programming language is here. After the Objective-C, it’s the ‘second’ official language for app development in the Apple ecosystem.

Swift 5.0 brings several new features such as ABI Stability and other functions. The latest version comes with updated package manager and compiler. Today, I will share some major features and other updates every mobile developer should know.

Read: Why You Should Learn Swift Programming Language?

Swift 5: Important Features and Changes

1. ABI Stability

ABI stands for Application Binary Interface, a binary equivalent of an API. It aims to make future apps easier to build and a lot smaller in size.

As you might know, most of the codes written in apps are already available as part of iOS, frameworks, and libraries. With ABI, a user won’t have to download all the application code. The app will just have to use the binary code already present and that’s it.

2. Integer Multiples With “isMultiple(of:)”

Swift 5 comes with a new function isMultiple(of:) for testing if a given integer is a multiple of another number. This function is free from redundancy and thus improves the readability of the code. Regardless to say, it’s now also discoverable by the auto-complete feature of XCode.

Sample Usage:

let number = 42
if number.isMultiple(of: 2) {
print("\(number) is even!")
}

3. Filter And Count With “count(where:)”

The problems with current collection functions such as map(_:), reduce(_:) and filter(_:) are — they make the code too verbose and wasteful. Even if we just want to count, we need to filter first, and this is where ‘count(where:) comes in. This function allows us to filter and count with just one function call.

Sample Usage:

let scores = [1, 3, 8, 2, 5, 6, 2, 10]
let count = scores.count(where: { $0 > 5 })
print(count)

Output = 3

Also Read: Android Development vs iOS Development: Which one is Better?

4. Package Manager Updates

Swift 5 brings a number of updates in Swift Package Manager. It includes target-specific build settings, customized deployment targets, dependency mirroring, etc.

It now allows you to import libraries in a REPL using the run command without thinking about building an executable.

5. Other Language and Compiler Updates

Swift 5 comes with Exclusivity Enforcement by defaults. It allows exclusive access to memory for both debug and release builds. Swift 5 supports dynamic callable types and helps improve interoperability with languages like JavaScript, Python, and Ruby.

Some other updates include Literal initialization via coercion, Identity key path, etc.

Recommended: An Introduction to Functions in Swift Programming Language

Ending Words

Overall, Swift 5 comes with lightweight syntax and combines powerful type inference and pattern matching. If you’re impressed by the features of Swift 5 and looking for migration, there’s nothing to worry about.

You can just use the XCode 10.2’s code migrator and it will handle the rest automatically. Swift 5 is compatible with Swift 4, Swift 4.1 and Swift 4.2. So, which features of Swift 5 you liked the most? Do let us know in the comments below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.