Concurrency in Swift: Using the new async/await syntax
Blog post from LogRocket
Swift, introduced by Apple in 2014 and designed by Chris Lattner, aimed to be versatile for both teaching programming and building OS software. Since becoming open-source, Swift has evolved, yet lacked native concurrency and parallelism primitives until the recent introduction of async/await keywords. These keywords simplify concurrent programming by allowing tasks to be offloaded to background threads, preventing UI freezing in iOS apps. Apple's Grand Central Dispatch (GCD) has traditionally been used for managing task parallelism, but async/await offers a more readable and less error-prone approach to concurrency. With the release of iOS 15 and macOS 12, developers can leverage async/await to write cleaner and more efficient concurrent code. This shift aligns with advancements in CPU design, such as increased core counts, which enhance the relevance of concurrency in modern computing. Swift's new concurrency model, including the introduction of actors to manage shared mutable state safely, promises significant improvements in writing concurrent applications.