Network Layer Completion Blocks
AppStore JSON APIs
In this lesson, we'll go over how to start populating our cells by using the result set fetched from the iTunes API. This is relatively easy and only requires us to capture the results into a local variable and modifying cellForItem:indexPath. Once we're done with that, we move onto completion blocks and a network layer that helps us separate logic into a different class. This is extremely helpful in keeping your files lean and easy to maintain. Enjoy.

Comments (9)
weare99
4 years ago
Hi Brian maybe the DispatchQueue.main.async call is better in the NetworkLayerModel -> you only call that one time and the error rate to forget the call in MainVC is not available anymore. I hope you understand my issue :)
ezechinwa
4 years ago
Wow, Awesome tutorial, Completion block is awesome
Janek Kruczkowski
4 years ago
Brian correct me if I' am wrong but I think that you should use weak self var in fetchApps method closure when you are reloading collection view to avoid potential memory leaks?
c.smith
3 years ago
Same question @ 19:18 for example, when you write closures I believe that you are supposed to write [weak self] (results) in to avoid memory leaks.
skuenstler
4 years ago
Brian, great tutorial! One tiny question: at minute 20:51, wouldn't it make more sense to return `completion([], err)` instead of `completion([], nil)` ??
rgarcia
4 years ago
I have the same question ?
nombienombie
4 years ago
I imagine the reason for using item on a collection view and not row is that a collection view may be horizontal where as a table view would always we vertical. If we are using a horizontal collection view it wouldn't make sense to describe a cell as a row when they are all technically on the same row / axis?
Brian Voong
4 years ago
nombienombie
4 years ago
Thanks!
e.tavares
4 years ago
Hii! Why do You use Service.shared.<function> if you could use just Service.<function>? thank you
Brian Voong
4 years ago
Yan Cervantes
3 years ago
Hi Brian, great tutorials! Thanks! how can I check if my internet connection is low or bad?
Brian Voong
3 years ago
Yan Cervantes
3 years ago
thanks!!!
frankusu
3 years ago
Hey Brain thanks so much for this knowledge! Why do we use URLSession.shared.dataTask and can't just use URLSession.dataTask ?
frankusu
3 years ago
Hey Brian, I know we have to update UI on the main thread, but since when did we leave the main thread? I don't understand when a separate thread was created, we never explicitly created it right? Could you explain when we need to use DispatchQueue.main.async ?
Brian Voong
3 years ago
frankusu
3 years ago
Thank you, Brian, that clear things up
HELP & SUPPORT