Skip to content

Example Async/Await recover data from online JSON

Notifications You must be signed in to change notification settings

goojoob/AsyncAwait

Repository files navigation

AsyncAwait

Example using Async/Await to recover data from online JSON


JSON Online

https://random-data-api.com/api/computer/random_computer?size=4


Created with 🛠️


MODEL

{
  "id": 4749,
  "uid": "92933cda-5396-4ab4-ae72-4b61b1651efb",
  "platform": "macOS",
  "type": "workstation",
  "os": "High Sierra (10.13)",
  "stack": "Linux, Debian 10.10.3"
}
struct Computer: Identifiable, Codable {
    var id: Int 
    var uid: String
    var platform: String
    var type: String
    var os: String
    var stack: String
}

ASYNC/AWAIT

.task {
    do {
        computers = try await getNetworkData()
    } catch let error {
        fatalError("\(error)")
    }
}
func getNetworkData() async throws -> [Computer]

ASYNCIMAGE

Image view that asynchronously loads and displays an image.

AsyncImage(url: URL(string: imageURL)) { image in
    image
        .resizable()
        .aspectRatio(contentMode: .fit)
        .frame(width: 200, height: 200)
        .clipShape(RoundedRectangle(cornerRadius: 30, style: .continuous))
} placeholder: {
    ProgressView()
        .progressViewStyle(.circular)
        .scaleEffect(1.5)
}

About

Example Async/Await recover data from online JSON

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages