Learn Courses My Dashboard

SirNova's First App Challenge - NBA Stats

Ok so here goes with my first app challenge. I’ve been learning Swift code (both SwiftUI and UIKit) for about 2 months now and feel like this would be a good time to take on a challenge. I may not have all the skills yet to produce a working app in time for the challenge deadline, but surely that’s part of the fun…right? Anyways I think the best place to start is with the data and API’s so here goes.

I guess the best place to start is with the recommended data source, SportsData.io. So after signing up for a free trial, I’ve started to look over the API documentation. Wow there is a lot in there, but as a developer in other languages, I certainly appreciate the need not only for documentation, but for GOOD documentation that is clear, precise, and well organised.
After opening up a few API call points, it’s getting a bit confusing without seeing the data in a logical format. Time to open up a JSON parser. I’ve gone for one recommended by Chris himself in the YouTube app build, JSONLint. That’s much better and makes so much more sense to understand what data is available.
My first thoughts are that this is going to take a few different API calls to get different data depending on the screen. It also looks like the ‘Data Dictionary’ is going to become a best friend. I can see why this is a recommended data source, but I think I would be foolish not to look at other sources. To Google it is…

So the first API website I click on is RapidAPI. It seems pretty good and looks like it gives some definition as to the end-points available, but nowhere near that of SportsData.io. Also it only allows up-to 25 API calls per day for free until they begin to charge. Although I don’t particularly plan on accessing the API’s and data all that much, I think at this stage it would be wise to stay away from any payment plans.

The next site I check is NBASense.com. This one says it is a documentation site for connecting directly into the NBA’s own API’s, sounds promising. On further inspection, it recommends using PHP 7.0 to connect to the API’s, however it does state that the data gets returned in JSON format so I think this could work. I started to look through some of the examples of the API’s available, but none of them seem to work and return any data, they just hang in the browser.

I think I’m going to stick with the original recommended data source. It seems to be the most comprehensive data, is completely free to use (as long as you don’t mind scrambled score data), and has a good level of documentation. I think the next thing is to start building the API calls in Swift.

1 Like

I start by making a Constants file to hold onto the API Key as well as other crucial data that I’ll need to refer back to later when calling on the data. For now, I’ve left a static date in my API URL, but have left a mark to update this to a variable date later in development.

I then set up a ‘Game’ structure so that I can create objects based on each game contained in the API call. This is my first time parsing JSON in SwiftUI but have taken the lead from the YouTube One Day Build app that I previously built. I think I have everything set up correctly (I don’t have any Xcode errors at the moment) so I think the next step is to set up a model which I can then use to test the API call is working successfully, but that will have to wait until tomorrow now.