Overview
Early in this month of June was WWDC 2022. After a huge update in iOS 16, Now, let’s talk about the some technical updates about the SWIFT 5.7.
Swift Playgrounds
Swift playground allows users to create applications directly from Swift playground and submit it to the App-Store.
Swift Packages update
- Trust on First User (TOFU)
- New security protocol where the fingerprint of a package is now being recorded when the package is first downloaded.
- Report an error if the fingerprint is mismatched.
Plugins
- Command Plugins
- Providing more secure build tools and extensible
- Used for documentation generation, source code re-formatting, etc
- Tool Ex: SwiftLint
import Foundation import PackagePlugin //Creating a struct that conforms to CommandPlugin protocol. @main struct GenerateMyPlugin: CommandPlugin { func performCommand(context: PluginContext, arguments: [String]) throws { //init code } }
- Build tool Plugins
Performance Improvements
- Build Time
- Faster type-checking for generics
- Run Time
- Optimized protocol conformance checking
Concurrency
Can be deployed and used with all OS.Update in Actors, this year introduces Distributed Actors.
- Actors
- Actors allow you to isolate your data using thread-safe, and concurrently executing code.
- Actors allow you to isolate your data using thread-safe, and concurrently executing code.
- Distributed Actors
- Similar to (local) actors bcz they encapsulate their state with communication exclusively through asynchronous calls
- Ex.:
distributed actor User { var name: String distributed func addUser(str: String) -> User { //init code here } }
- Actors Prioritization
- Actors now execute the highest-priority work first
Async Algorithms
- New open-source package that brings concurrency to a set of existing sequence algorithms.
- Ex:
for await (id, name) in zip(idxs, names) { print("\(id) with \(name)" }
- Also, we can use a try/catch pattern to handle things like network failures, data streaming etc.
- Ex:
do { for try await (video, preview) in zip(videos, previews) { try await upload(vid, preview) } } catch { //Handle Failure }
- Merge
Ex:for try await message in merge(primaryAcc.messgaes, secondaryAcc.messgaes) { displayPreview(message) }
Regex Builder
- Huge improvement to the developer experience around regex.
- With RegexBuilder, we can use an expressive specific language to build regular expressions.
- Ex:
Updates in Swift 5.7
- Important update of optional unwrapping
Ex. => if let x now, became if let x - No need to manually specify a closures result type
- Update scope of some and any keywords
Ex:
For Anyprotocol X {} struct Example: X {} let a: X = Example() //New: Works, Before Swift 5.7: Error let a: any X = Example() //New: 'any x' is an explicit existential type
- For more : Changelog.md