I am attempting to write a technical dictionary app and am basing it on the Moonshot app in 100 days of SwiftUI. My data structure is simple:
struct Definition: Codable, Identifiable {
let id: Int
let term: String
let meaning: String
}
My test .json file attempts to work with that structure:
{
1:
{
"id": 1
"term": "a",
"meaning": "The first letter of the alphabet."
},
2:
{
"id": 2
"term": "bird",
"meaning": "Birds are a group of warm-blooded vertebrates constituting the class Aves (/ˈeɪviːz/), characterised by feathers, toothless beaked jaws, the laying of hard-shelled eggs, a high metabolic rate, a four-chambered heart, and a strong yet lightweight skeleton. ."
},
3:
{
"id": 3
"term": "football",
"meaning": "Football is a family of team sports that involve, to varying degrees, kicking a ball to score a goal."
}
}
The JSON file won't decode using:
let definitions: [Int: Definition] = Bundle.main.decode("Test.json")`
and I've tried many variations. It looks very similar to the astronauts.json file in the Moonshot app but something is clearly missing.
Any help is much appreciated.
Cheers
Steve