Features in Swift 5.0

Divesh Singh
2 min readMay 5, 2020

1. ABI Stability

ABI enables you to reduce the build size and code of your application, Most of the code is already available with your iPhone devices as part of iOS. ABIs are important when your app uses external libraries and the library got later updated and if the updated library uses the same ABI, so you don't need to worried about this as you don’t need that compile library again.

It enables binary compatibility between applications and libraries compiled with different Swift versions.

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

Swift 5 comes with a new function isMultiple(of:) for checking if a given integer is a multiple of another number. before swift 5 we have to do some workaround for this.

if firstNum = 5
if secondNum = 15
if firstNum.isMultiple(of: secondNumber) {
print("\(secondNum) * \(firstNum / secondNum) = \(firstNumber)")
}

3. The Result Type

Result type combined possible return values and errors in one object.

enum ConnectiError: Error {
case noNetwork, noDatabase
}

let networkSuccess = Result<String, ConnectionError>.success("Network avai!")

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

Sample Usage:

let ages= [11, 34, 38, 22, 35, 86, 92, 100]let count = ages.count(where: { $0 > 15 })print(count)Output = 7

5. Flatten Nested Optionals With “try?”

try? in Swift 5 doesn’t create nested optionals

Sample Usage:

if let engine = (try? shop?.getItem()) as? Food {// it’s done}

6. The New “compactMapValues()” Function For Dictionaries

it discards nil value while mapping

7. Raw strings

To use raw strings, place one or more # symbols before your strings, like this:

let air = #”The “air” in “XYZ” moving ahed.”#

8. Using New Character Properties

New API introduces to check if the string is a digit or not, “isNumber” to check if every character is a digit.

9. Renaming Dictionary Literals

Swift 5 renames DictionaryLiteral to KeyValuePairs

If you find this article is helpful please do not forget to share, recommend, and clap.

--

--

Divesh Singh

Postgraduate from JEC Jabalpur || iOS and macOS developer, traveler |||| EM at Darwinbox | Ex-Samsung || Ex - Optimize IT Sys | Ex - R Systems