I have created an app much like this one but in my “Recipe” data, i have included a ‘summary’ property where it is an array of String:String - I have tried several ways to implement it in my Models ‘Recipe’ file. Chris has added a property ‘highlights’ which is an array of Strings but i don’t know how to implement this property, which looks like this in my json file within each Recipe:
“summary”: [
{“rating”:“5”},
{“serves”:“4”},
{“preparation”:“7 minutes”},
{“cooking” : “3 minutes”}
],
This information is to be used on the RecipesView page to display rating, servings, prep and cooking time but i don’t know how to implement in in the Recipe Model or parse it.
Any help would be appreciated.
FYI on what i have tried:
if i use: var summary: [String:String], i get this error:
typeMismatch(Swift.Dictionary<Swift.String, Swift.String>, Swift.DecodingError.Context(codingPath: [_JSONKey(stringValue: “Index 0”, intValue: 0), CodingKeys(stringValue: “summary”, intValue: nil)], debugDescription: “Expected to decode Dictionary<String, String> but found an array instead.”, underlyingError: nil))
if i use: var summary:[Summary],
then i add this class:
class Summary: Identifiable, Decodable {
var id: UUID?
var rating: [String:String]
var serves: [String:String]
var preparation: [String:String]
var cooking: [String:String]
}
i get this error:
typeMismatch(Swift.Dictionary<Swift.String, Swift.String>, Swift.DecodingError.Context(codingPath: [_JSONKey(stringValue: “Index 0”, intValue: 0), CodingKeys(stringValue: “summary”, intValue: nil), _JSONKey(stringValue: “Index 0”, intValue: 0), CodingKeys(stringValue: “rating”, intValue: nil)], debugDescription: “Expected to decode Dictionary<String, String> but found a string/data instead.”, underlyingError: nil))
Same error, either way
Please help