Skip to content

Instantly share code, notes, and snippets.

@laevandus
Created November 8, 2023 10:20
Show Gist options
  • Save laevandus/6291cf48c42112b4cda32845b83407c1 to your computer and use it in GitHub Desktop.
Save laevandus/6291cf48c42112b4cda32845b83407c1 to your computer and use it in GitHub Desktop.
struct ContentView: View {
// Demo: first load leads to an error
@State private var showsError = true
var body: some View {
ContentPrepareView {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
}
.padding()
} task: {
try await Task.sleep(nanoseconds: 3_000_000_000)
// Demo: Retrying a task leads to success
guard showsError else { return }
showsError = false
throw LoadingError.example
}
}
}
enum LoadingError: LocalizedError {
case example
var errorDescription: String? {
"The connection to Internet is unavailable"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment