Portfolio 2 Week 14: News API Sprint 4
- Goh Qi Xun

- Jan 24, 2021
- 3 min read
Back with another sprint, Sprint 4 our last sprint! Just like every start of the sprint, my group discussed on what we are planning to do and what is needed to completed (of course everything). After discussion, I must be able to finish my News, Redeem Page (back-end), Games (back-end) at the end of this sprint which I hope to get it done by next week as we have yet to do any validation.
The start of this Sprint, I worked on the News API. My initial thought that it will be easy because I have already done the COVID-19 page. I was very wrong... The whole data structured in a different and more complex way with images I need to retrieve and convert into UIImage before display.
Designing wasn't an issue here because tableview are usually easy to constraint as we only need to do 1 cell and it will duplicate on it's own. This is the design:

Issue #1
The first issue I was faced trying to create the class for the API. This is my first time working with such complex API that has array in it. I tried using "quicktype" to convert JSON to swift.

I was able to run the code but I am constantly getting invalid data format even though it seems fine to me and it's looks fine to me and is generated online. I wasn't able to find any issue and was trying to fixed this for 1 whole day. I went to asked my friends which is way very good with Swift and he suggest me to create a sample data and try to enter copy one of the information. Instantly got this fixed as I realise that the date is in string and not Date format. I felt like I've wasted a lot of time on this.

Issue #2
Since the images must be loaded from URLToImage, So the process is that I must load and append before the other details are loaded if not it will always display as NULL. I fixed this by allowing the images to be loaded and append before I load the other information into the Cell data.
Issue #3
During some days the news crash, sometimes it doesn't. I couldn't seems to find the issues at the start until I went breakpointing and printing everywhere. I realise that sometimes the images are null but I always tried to force unwrapped, load and append which mixed up every thing. I was able to fix this but just simply adding a if statement that if it's null just don't display. (Although it took me quite sometime to find out issue)
Issue #4
Since the Search bar information are according to the news title, I append the title accordingly when specific letters are in the search bar. The issue here is that it always display the first item even though I search for another. Turn out is that I forget that I need to change my each cell's data to filtered data array but instead, I am still using the main "articles" array which always get the first article[0] if there's only 1 item.
I feel that this took up most of my time other than fixing the GitHub and cocoa pods issue. I still manage to get it done and this is how the final product looks like:





Comments