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
12345678910import Foundationimport PackagePlugin//Creating a struct that conforms to CommandPlugin protocol.@mainstruct 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
- 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:
123for 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:
1234567do {for try await (video, preview) in zip(videos, previews) {try await upload(vid, preview)}} catch {//Handle Failure}
- Merge
Ex:123for try await message in merge(primaryAcc.messgaes, secondaryAcc.messgaes) {displayPreview(message)}
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 Any123456protocol X {}struct Example: X {}let a: X = Example() //New: Works, Before Swift 5.7: Errorlet a: any X = Example() //New: 'any x' is an explicit existential type - For more : Changelog.md