Created
November 11, 2024 13:02
-
-
Save lucianoschillagi/6ba8d5b862bd2a26cdf3473109391035 to your computer and use it in GitHub Desktop.
SwiftUI View Lifecycle methods → task(priority:)
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
import SwiftUI | |
struct ContentView: View { | |
let url = URL(string: "https://dc4p.store")! | |
@State private var message = "Loading..." | |
var body: some View { | |
Text(message) | |
.task { | |
do { | |
var receivedLines = [String]() | |
for try await line in url.lines { | |
receivedLines.append(line) | |
message = "Received \(receivedLines) lines" | |
} | |
} catch { | |
message = "Failed to load" | |
} | |
} | |
.padding() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment