Trying to make an expandable table in Swift using API calls

Hello, This is for a JP Morgan Chase Take home quiz for an iOS developer role.

There are two parts to this test:

  1. take this JSON data with NYC high school SAT scores (https://data.cityofnewyork.us/resource/f9bf-2cp4.json) and put it into a table.
  2. when a user clicks on a school from this table they should be able to view statistics on the SAT scores about said school (SAT statistics in the same JSON call from part 1).
  • to accomplish part one of this test I used this YouTube video titled "How To Pass API Data To TableView Cells In Swift IOS" (https://www.youtube.com/watch?v=0H78ktM97yU&t=646s) to make a table with all the schools in the JSON file. Here is my code that is the same as this video except with the API of the schools instead of the API from the YouTube video.
  • to accomplish the second part of this test I found this YouTube video (https://www.youtube.com/watch?v=samoIVHg6yQ&t=533s) on expandable tables. This is where I am struggling though. I figured it wouldn't be hard to take the code from this YouTube video and implement it into the code I made from the YouTube video I used for part one.... but... I was soooo wrong. Here is the code from this YouTube video

My first thought on how to implement the code from the "Creating Expandable TableView Cells (Collapsable) - Xcode 12, Swift 5, iOS Development 2022" YouTube video into the code I made from the "How To Pass API Data To TableView Cells In Swift IOS" was to edit the Model.swift file in my code. However, when I do that I get an error from Xcode saying "Return from initializer without initializing all stored properties" cuz I added in the 'init' subclass (I think that is what it is called). Then I tried to edit the model again and I didn't get an error, but this time my emulator just doesn't show any code...?

Does anyone have any advice on how to get this code to work? In case this is confusing, here is an image of what I have now and what I am trying to accomplish in my readme along with the prompt I got from JPMC.

(also-- I already got rejected for this role 2 weeks ago bc I failed the test, but now I am trying to figure out how to solve it anyways for my own learning development, so you're not helping me 'cheat' by helping me with this. I just want to learn how to get APIs to work cuz I know how important that is for iOS jobs)

PS: sorry for the wonky formatting Apple forums don't allow you to post YouTube videos or JSON files so I had to get crafty.

My first advice would be don't try to work with expandable TableView cells if you're new to Swift, Table Views etc. Tables with varying height and content are a pain. The request is that a tap on a school shows more information about that school. So add a detail view segue when you tap on a table item, and have that detail view display all the detailed school information. On the phone, that will take up an entire screen, with a back button on the top left, you'll put the name of the school in the top middle and you have a whole lot of space to display the per-school details on their own, outwith the table.

There are a whole lot of tutorials on displaying varying levels of database detail for iOS using more prosaic information display methods.

However, when I do that I get an error from Xcode saying "Return from initializer without initializing all stored properties" cuz I added in the 'init' subclass (I think that is what it is called). Then I tried to edit the model again and I didn't get an error, but this time my emulator just doesn't show any code...?

General comment, not looking at your code.

When you define a class or a struct, you usually define properties (var). Such as:

var name: String

Those are called stored properties (as opposed to computed var, but that's another point.

When you do so, you have to initialise the var in the init:

init() {
  name = ""
}

As explained in Swift reference:

Classes and structures must set all of their stored properties to an appropriate initial value by the time an instance of that class or structure is created. Stored properties can’t be left in an indeterminate state.

But you can also do it with a default initialiser, declaring:

var name: String = ""

Much simpler.

Trying to make an expandable table in Swift using API calls
 
 
Q