ExampleAwaitAsync
user_1756274
swift
3 years ago
423 B
11
Indexable
class API {
...
func fetchServerStatus() async throws -> ServerStatus {
let (data, _) = try await URLSession.shared.data(
from: URL(string: "http://amazingserver.com/status")!
)
return ServerStatus(data: data)
}
}
class ViewController {
let api = API()
let viewModel = ViewModel()
func viewDidAppear() {
Task {
viewModel.serverStatus = try await api.fetchServerStatus()
}
}
}Editor is loading...