Introducing Swift 5.2
Introduced by Apple (on March 24, 2020), Swift 5.2 has handy features focused on improving the developer experience and providing additional language features. Some of the new language features seem to be oriented toward enhancing the functional programming style. Let's review these new features with some code examples.
Key path expressions as functions
This new feature allows developers to use key path expressions such as \Root.value wherever (Root) -> Value functions are allowed. Let's see it in action.
Let's create a Car struct with two properties, brand and isElectric:
struct Car {
let brand: String
let isElectric: Bool
}
Then, let's instantiate an array of Car structs with two cars, one that's electric and one that's not electric:
let aCar = Car(brand: "Ford", isElectric: false) let anElectricCar = Car(brand: "Tesla", isElectric: true) let...