Hey,
I am trying to add new information I added to my JSONs to my Struct in SwiftUI but every time I do it then comes with an error that the struct doesn't conform to codable but when I remove it, it works?
Here is the struct:
struct Recipe: Identifiable, Codable {
let id: Int
let name: String
let creator: String
let serves: Int
let ingredients: [Ingredient]
let methods: [Method]
let imageURL: URL
enum CodingKeys: String, CodingKey {
case id, name, creator, serves, ingredients
case methods = "method"
case imageURL = "imageurl"
}
}
struct Ingredient: Codable {
let name: String
let quantity: Double
let measurement: String
}
struct Method: Codable {
let step: Int
let text: String
}
enum RecipeSelection: String, CaseIterable, Identifiable {
case vegan
case breakfast
case lunch
case dinner
var id: String { self.rawValue }
var name: String { self.rawValue.capitalized }
var menu: String {
switch self {
case .vegan: return "Vegan"
case .breakfast: return "Breakfast"
case .lunch: return "Lunch"
case .dinner: return "Dinner"
}
}
}
hope you can help.
best, Imran