Press ESC to close

Swift 5.7

Hello friends, in this article, we will talk about the innovations that come with Swift 5.7. With the 5.7 version, many new developments were made. You can review all the changes here. Here I will share the most notable features.

If Let Değişikliği

There are many ways to make an Optional variable unoptional. One of them is if let. You can make an optinal variable unoptional with if let as follows.

import UIKit

var animal: String? = "Dog"

if let animal = animal {
    print(animal)
}

Now we don’t need to equate the variable we created with if let to the optional variable instead. You can use as below.

 

import UIKit

var animal: String? = "Dog"

if let animal {
    print(animal)
}

More details can be found here.

Multi Statement Closure Parameter

With this change, we don’t need to specify the parameter to return from a closure. As you can see in the example below, I can run it without specifying what type to return.

import UIKit

let numbers = [54, 90, 110, 72]

let values = numbers.map { number in
    return "\(number)"
}

Before Swift 5.7, I had to specify this type as follows.

import UIKit

let numbers = [54, 90, 110, 72]

let values = numbers.map { number -> String in
    return "\(number)"
}

More details can be found here.

You can find more articles with Swift here. If you have any questions, you can contact me by sending an e-mail or comment. 

 

Leave a Reply

Your email address will not be published. Required fields are marked *