Apologies
You must be signed in to watch this lesson.
Dependency Injection and Error Checking
AppStore JSON APIs
As a consequence of introducing new features in our application, we've also introduced some nasty show stopping bugs. In this lesson, I'll go over how to catch the errors in our api calls to effectively determine what the necessary fixes need to be. Lastly, I'll briefly give an example of how to implement dependency injection for our AppDetailController component. There are many advantages of doing this but I just wanted to give you a quick taste of what it looks like for now.

Comments (9)
TWei
5 years ago
Finally understand DI. Thanks Brian.
richardbranson
5 years ago
Programmers are really bad at naming thing. Dependency Injection, really? I was afraid of this topic but it is so damn easy. Why name a simple thing so complicated and terrifying? All thanks to you Brain!
gabedelvillar
4 years ago
Right?!!!! Same here boss.
LionCode
5 years ago
Thanks Brian, I like a lot your way of teaching.
tonytech
5 years ago
for my fellow app builders, this seemed to work for me let x : Int = appId ?? 0 let myString = String(x) appDetailController.appId = myString
ZpecterZ80
5 years ago
This worked for me too: appDetailsController.appId = searchResults[indexPath.item].trackId.description
tonytech
5 years ago
i think the api is outdated. im not getting the complete page rendering
Tokyojogo
5 years ago
Hi Brian, I have a question/concern. I added a print statement in appDetailCell and I see that when I click on an app and goes to appDetailController, the print statement is being fired 3x. I downloaded your project and added the statement to check and its the same. Why is appDetailCell being called 3x? Shouldn't it be just once? Is this ok and correct? Thank you.
waynezong
5 years ago
Hi! I found the same behavior and I think it's absolutely fine. My guess is that when you open the collection view controller, it will automatically load its data. So it'll fire once. Because we are downloading all the app informations and images on the background thread, at this moment you won't see anything on your cell. But once when the download is finished, it will trigger the completion block, in which we explicitly called 'self.collectionView.reloadData()' in order to pass the app details we parsed from json to the cell. This will fire it again. Depending on the network speed, our app details/screenshots/reviews may be loaded separately, so the collection view may be loaded even more times. I think a better solution will be what Brian did on the Apps page where we present an activity indicator view before all the data is finished downloading. This is my assumption, hope it will help! :)
Stewart Lynch
5 years ago
Why do you change from let to var when making optionals? Leaving it as let seems to work fine for me.
Brian Voong
5 years ago
Stewart Lynch
5 years ago
I didn't add any custom initializers and I still get the same results.
Brian Voong
5 years ago
jdhindsa
4 years ago
In the init() function, why does the super.init() call have to come after the line where you set the local appID variable? I don't get that..
wsl100624
4 years ago
Hi Brain, I noticed there is always 3 cells in this collectionView. But what if the app doesn't have preview data or review data. How do you disappear those cells? One solution might be set the height of the cell to 0?
Brian Voong
4 years ago
wsl100624
4 years ago
Thanks for the quick response, Brian! Sorry I had a typo on your name:)
HELP & SUPPORT