Created
April 10, 2024 17:17
-
-
Save rintoandrews90/9bbd066643eb9a56d0e1ca11f8cee326 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 TaskExample: View { | |
@State private var source = "" | |
var body: some View { | |
ScrollView { | |
Text(source) | |
} | |
.task { | |
await fetchSource() | |
} | |
} | |
func fetchSource() async { | |
do { | |
let url = URL(string: "https://hws.dev/inbox.json")! | |
let (data, _) = try await URLSession.shared.data(from: url) | |
source = String(decoding: data, as: UTF8.self) | |
} catch { | |
source = " Failed to fetch apple.com" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment