The Swift Cooperative

Authors publishing advanced articles on Swift and SwiftUI application development.

Follow publication

Member-only story

Async/Await and MainActor Strategies

Michael Long
The Swift Cooperative
13 min readApr 23, 2023

--

Photo by amirali mirhashemian on Unsplash

The View Model

class ContentViewModel: ObservableObject {

@Published var accounts: [Account]
@Published var message: String?

let loader: AccountLoader

init(loader: AccountLoader) {
self.accounts = []
self.loader = loader
}

func load() async {
do {
accounts = try await loader.load()
message = nil
} catch {
message = "Unable to load"
}
}

func process(_ accounts: [Account]) {
self.accounts = accounts
}
}

Swift Intermediate Language

--

--

The Swift Cooperative
The Swift Cooperative

Published in The Swift Cooperative

Authors publishing advanced articles on Swift and SwiftUI application development.

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

Responses (10)

Write a response