My app parses a number of APIs in Swift some of which share similar names for dictionaries and/or arrays.
I can't control the names of the incoming JSON dictionaries arrays as they come from API endpoints. Currently I have one utility class that processes all these APIs. How can I parse APIs that share common names?
Here is what I'm using for one API.
struct aVideo: Codable {
let page, totalResults, totalPages: Int
let results: [Result]
enum CodingKeys: String, CodingKey {
case page
case results
}
}
// MARK: - Result
struct Result: Codable {
let popularity: Double
let voteCount: Int
let video: Bool
}
This other API uses the same key, Result and it is throwing an error.
// MARK: - WordInfo
struct WordInfo: Codable {
let word: String
let results: [Result]
let frequency: Double
}
// MARK: - Result
struct Result: Codable {
let definition, partOfSpeech: String
let synonyms, entails, hasTypes, derivation: [String]
}
Thanks for any suggestions.