Skip to content

Instantly share code, notes, and snippets.

@SebastianBoldt
Last active February 3, 2022 10:23
Show Gist options
  • Save SebastianBoldt/86b53bd678f75588b30cf4b48956c2c5 to your computer and use it in GitHub Desktop.
Save SebastianBoldt/86b53bd678f75588b30cf4b48956c2c5 to your computer and use it in GitHub Desktop.
struct ContentView: View {
@State var taskTrigger: Bool = false
var body: some View {
Button("Execute Task", action: {
taskTrigger.toggle()
}).task(id: taskTrigger) {
do {
let newText = try await getText()
print(newText)
} catch {
print(error.localizedDescription)
}
}
}
func getText() async throws -> String {
try await Task.sleep(nanoseconds: 1_000_000)
return "Text"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment