Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwiftUI Example #21

Closed
wmorgue opened this issue Mar 23, 2022 · 2 comments
Closed

SwiftUI Example #21

wmorgue opened this issue Mar 23, 2022 · 2 comments
Labels
question Further information is requested

Comments

@wmorgue
Copy link

wmorgue commented Mar 23, 2022

Please make a small example of an application using SwiftUI & Get.
Or can someone share a gist?

@ericlewis
Copy link
Sponsor

ericlewis commented Mar 24, 2022

@wmorgue not entirely sure what you mean, but here is a pseudo example.

import SwiftUI
import Get

let client = APIClient(host: "api.example.com")

struct User: Decodable {
  let id: String
}

struct ContentView: View {
  @State private var userId: String?

  var body: some View {
    if let userId = userId {
      Text(userId)
    } else {
      ProgressView()
       .task {
         do {
           let user: User = try await client.send(.get("/user/testing")).value
           self.userId = user.id 
         } catch {
           print(error.localizedDescription)
         }
       }   
    }  
  }
}

@wmorgue
Copy link
Author

wmorgue commented Mar 24, 2022

@ericlewis oh gosh, it works for me.
Thank you 🤝

@kean kean added the question Further information is requested label Mar 24, 2022
@kean kean closed this as completed Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants