Im trying to get my head around the new Codable feature Apple has added but Im not able to solve this problem. I have a json output which is like this
{
"Afpak": {
"id": 1,
"race": "hybrid",
"flavors": [
"Earthy",
"Chemical",
"Pine"
],
"effects": {
"positive": [
"Relaxed",
"Hungry",
"Happy",
"Sleepy"
],
"negative": [
"Dizzy"
],
"medical": [
"Depression",
"Insomnia",
"Pain",
"Stress",
"Lack of Appetite"
]
}
}
}
and I have a structure that is like
struct Strain: Codable {
var name: String
var id: Int
var race: String
var flavors: [String]
var effects: [String: [String]]
}
so obviously it will fail because there is no name key inside my json. The name should be "Afpak", I have looked around but most tutorials didnt give any example on how to solve this problem, they just did [String:Strain]
which is not what I need. Is there anyway set the key of my dictionary to my name variable?