Answer the question
In order to leave comments, you need to log in
Parsing Json, with nested reference to another Json?
Greetings
Tell me how to parse json, in which there is a link to another json, in one request. Since I fill from this Json CollectionView, and if I make a second request, then I need to make crutches with the correct display of pictures to cells. The situation is as follows
1. I have a file structure
struct Headline: Codable {
var articles: [Article]
}
struct Article: Codable {
let id: Int?
let date, dateGmt: String?
let links: Links?
enum CodingKeys: String, CodingKey {
case id, date
case dateGmt = "date_gmt"
case links = "_links"
}
}
struct Links: Codable {
let linksSelf, collection, about: [About]? // []
let wpFeaturedmedia: [Author]?
enum CodingKeys: String, CodingKey {
case linksSelf = "self"
case collection, about, author, replies
case wpFeaturedmedia = "wp:featuredmedia"
}
}
struct Author: Codable {
let embeddable: Bool?
let href: String?
enum CodingKeys: String, CodingKey {
case href
case embeddable
}
}
static func getArticles(url: URL?, completion: @escaping ([Article]?) -> Void) {
url?.get(completion: { (result: Result<[Article], ApiError>) in
switch result {
case .success(let headline):
print("\n News Api extension getArticles headline \(String(describing: headline.count))")
completion(headline)
case .failure(_):
print("\n News Api getArticles failure")
completion(nil)
}
})
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question