'Swift - Is there a way to remove data from API that doesn't contain a certain key?
I am using Tasty recipes/list API from (https://rapidapi.com/apidojo/api/tasty/).
Unfortunately, this API is a mess (but it is the only one I could find that allows you to search for recipes by keyword and return a list of ingredients and instructions. As well as have a response time of under 8 seconds).
When I do a search it will either return a list of recipes or an item with a list of recipes. I am just trying to retrieve a list of recipes (and remove the ones that contain a list). I've found that the data I want contains a list of 50 items while the ones I do not want contain 28 items.
So would there be a way to check how many items that piece of data has and remove it from the list of data I am retrieving?
I have the following data structure:
struct Response: Decodable, Encodable {
let results: [Data]
}
struct Data: Decodable, Hashable, Encodable {
let name: String
let thumbnail_url: String
let sections: [Section]
let instructions: [Instruction]
let num_servings: Int
let prep_time_minutes: Int?
let cook_time_minutes: Int?
let total_time_minutes: Int?
}
struct Section: Decodable, Hashable, Encodable {
let components: [Ingredient]
}
struct Ingredient: Decodable, Hashable, Encodable {
let raw_text: String
}
struct Instruction: Decodable, Hashable, Encodable {
let display_text: String
}
I can provide more info/code upon request. Thank you I appreciate it!
Here is a picture of the data it returns (from the RapidAPI link above)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

