Last active
February 3, 2022 10:23
-
-
Save SebastianBoldt/86b53bd678f75588b30cf4b48956c2c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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