Home > other >  display your github data using Github API / SwiftUI
display your github data using Github API / SwiftUI

Time:05-10

task to be done: Make your github data appear on the ContentView screen using the Github API.

struct TaskEntry: Codable  {
    let id: Int
    let title: String
}
    @State var results = [TaskEntry]()
    
    func loadData() {
            guard let url = URL(string: "https://jsonplaceholder.typicode.com/todos") else {
                print("Invalid URL")
                return
            }
            let request = URLRequest(url: url)

            URLSession.shared.dataTask(with: request) { data, response, error in
                if let data = data {
                    if let response = try? JSONDecoder().decode([TaskEntry].self, from: data) {
                        DispatchQueue.main.async {
                            self.results = response
                        }
                        return
                    }
                }
            }.resume()
        }

the above solution did not help in performing this task

  • Related