WWDC 2023: What’s New In Swift

It’s getting great!

Steven Curtis
5 min readJun 6, 2023
Photo by Ajoy Joseph on Unsplash

This article is intended as a companion to https://developer.apple.com/videos/play/wwdc2023/10164/ and does not replace it in any way.

If let and switch statements as expressions

Instead of using difficult to read Ternary expressions that some can find hard to read we can use inline if statements.

struct Account {
var balance: Double
}

let account = Account(balance: 500)

let status =
if account.balance < 0 { "debt" }
else if account.balance == 0 { "break even" }
else { "Profit" }

print("Your account is in \(status).")

Similarly we can use switch statements. Something like the below shows how we might use this:

enum WeatherCondition {
case sunny
case cloudy
case rainy
}

let weather = WeatherCondition.sunny

let advice =
switch weather {
case .sunny: "Feeling hot!"
case .cloudy: "Oooooooh"
case .rainy: "Don't forget your rain jacket"
}

print("Today's advice: \(advice)")

Improved error detection

I don’t have a better example than Apple’s here from the video. So I reproduce that here rather than bluffing anything else:

struct ContentView: View {
enum…

--

--