I have a JSON file which I have imported. All records in the json file have an item which is an array consisting of between 1 and 3 items. This is causing the list to fail as there are some records which have a single entry and other records can have 2 or 3. When I specifically reference element 0, the app runs, but if I go to element 2 or 3, the app expectedly crashes. Is there a way I can get app to ignore nil values and run through. Sample of JSON File
[
{
"id": 1,
"tla":"ABR",
"name":"Abbey Road",
"lines": ["Dockland Light"]
},
{
"id": 2,
"tla":"ACT",
"name":"Acton Town",
"lines": ["District", "Piccadilly"]
},
{
"id": 3,
"tla":"ALD",
"name":"Aldgate",
"lines": ["Hammersmith", "Metropolitan"]
}
]
The goal is to list all lines regardless if lines consist of 1, 2 or 3
List {
ForEach(self.allStations.dataStructure,id: \.id) { TubeLines in
Text("\(TubeLines.lines[0])")
.foregroundColor(Color.blue)
}
}