Carlos' NBA Stats App Journal

Hello there!

This is my first time trying a cwc challenge, so I’ll do my best to showcase what I’m currently working on.

I decided to work with the sportsdata.io API since it seems to be the easiest to use and it’s free.

To get all the data I needed for the basics requirements I used

  • Games By Date api
  • Standings api for the rank and wins/losses
  • Teams api for the Teams’ full name, logo url and conference.

Maybe I’m going to use other apis in the future to add more features to my app.

So far so good! I only tested the Teams api by displaying all the teams in the UIPicker for the Settings tab where you can pick your favourite team. I’ve also set a favouriteTeam property inside my MainTabBarController in order to keep track of the last selection that the user made.

Next up is the Standings tab…

You can do this! :+1:

Hello,

So into the Standings tab, the data I needed for this was:

  • The full name of the team
  • Its conference rank
  • Its logo
  • The win - losses count
  • The conference of the team

Unfortunately I couldn’t use a single struct to store all this data because it comes from two different apis, maybe it’s possible, but I decided to create two models, one for Team and one for TeamStats and I added the teamID as a join parameter between the two structs. This did the job.

The hardest part was laying out all the items inside the table view cells since I used Storyboard and I had to figure out the different measures in order to fit everything without any weird stretch or clipping.

For the team’s logo I used the SVGKit library that I found very easy to use.

Finally I also added added the little star close to the user’s favourite team.

This is what it looks like both in light and dark mode!

2 Likes

Very nice

Thanks man! :smiley:

1 Like

Alright so last tab, the Games tab.

So after checking that I was getting data back from the GamesByDate api, I decided to have a single function to retrieve the games and split the data into 3 different arrays, one for each day. When parsing the data I also built a little method to convert the DateTime format into what I needed.

In case you need it here it is.

private func changeDateTimeFormat(_ str:String) -> String {        
        let df = DateFormatter()
        df.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
        
        let date = df.date(from: str)!        
        df.dateFormat = "hh:mm a"        
        let string = df.string(from: date)
        return string
}

Then it was just a matter of laying down all the elements correctly. I stayed consistent with the design I used for the Standings tab so I decided to put a little star in the favourite team’s match cell.
I think it looks great!

Just for the light mode screenshots I had to use some hardcoded dates (May 31st and June 1st of this year) because right now there are no games, but I tested the dynamic date url in the dark mode screenshot the day before the finals’ game and it’s working properly!

PS: I fixed the games count label when there’s only 1 game it says “1 Game” not “1 Games” anymore :sweat_smile:

1 Like

Hello,

I decided to add a little feature to my app and so now when you tap on a team in the Standings tab it shows a detail view of the team’s stats and some more information about the team such as the stadium, the city and the main colors of the team displayed in a little colored circle.

This is probably going to be the final touch of this project.

3 Likes