I am making an api call to the github api to get the names of folders in a repository. I do not know how to extract the data from the api call and where to go from here. Any help would be appriciated!
Code:
func extractData() {
let url = URL(string: "https://api.github.com/repos/myrepository/myrepository/contents/folder")!
let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
if let error = error {
print("Error with fetching repos: \(error)")
return
}
guard let httpResponse = response as? HTTPURLResponse,
(200...299).contains(httpResponse.statusCode) else {
print("Error with the response, unexpected status code: \(String(describing: response))")
return
}
if let mimeType = httpResponse.mimeType, mimeType == "application/json",
let data = data,
let dataString = String(data: data, encoding: .utf8) {
print("Got data: \(dataString)")
do {
if let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
print(json["name"])
}
} catch let error as NSError {
print("Failed to load: \(error.localizedDescription)")
}
}
}
task.resume()
}