Member-only story
Understanding Structured Concurrency and Swift
The introduction of Swift 5.5 comes a new model for managing asynchronous programming. Although many anticipated new hardware announcements at Apple’s WWDC21, instead, we received a redux in how many of us will write code for Swift-based apps, including iOS and beyond. As we will see, these changes focus on implementing more structured code when it comes to asynchronous operations.
A Primer — Structured Variables
When Swift was first introduced in 2014, a challenging language feature to grasp was optional variables. Not being able to assign nil to non-optional values or do other seemingly straightforward tasks proved confusing and nuanced:
var item = "first"
item = nil //nil cannot be assigned to type String
Back then, no other c-based language applied the concept of unwrapping variables. However, the main goal of optionals was to provide better tools to express one’s ideas without falling prone to runtime errors like memory leaks or null pointer exceptions.
Optionals have improved the entire App ecosystem by providing basic rules developers can adhere to at compile-time. Fast forward to today and the concept of structured coding has made it’s to another essential aspect of iOS development — multi-threaded operations. Known as structured…