Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created June 6, 2022 20:51
Show Gist options
  • Save sturdysturge/2706162f779c8176ed38182a710c69a3 to your computer and use it in GitHub Desktop.
Save sturdysturge/2706162f779c8176ed38182a710c69a3 to your computer and use it in GitHub Desktop.
import SwiftUI
struct ContentView: View {
func forTryAwait() async {
do {
for number in try await asyncFunc() {
print("\(number.howHigh)")
}
} catch {
fatalError(error.localizedDescription)
}
}
func asyncFunc() async throws -> [Counter] {
return [Counter(howHigh: 10), Counter(howHigh: 7), Counter(howHigh: 4)]
}
var body: some View {
EmptyView()
.task {
await forTryAwait()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment