Apologies
You must be signed in to watch this lesson.
Loading + Caching Images with SDWebImage
Podcasts
Loading images and caching them into your app is one of the most common tasks for an iOS developer. You can build your own caching library, which isn't too difficult, or you can use one of the widely available ones off the internet. In this video, we will go ahead and install SDWebImage and see how easy it is to load an image with one line of code. SDWebImage also manages the caching of your images so you wont have to refetch data when you scroll up and down your lists.
<div class='filename'>Info.plist</div> !codebreak !syntax-highlight <key>NSAppTransportSecurity</key> <dict> <key>NSExceptionDomains</key> <dict> <key>mzstatic.com</key> <dict> <key>NSExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSIncludesSubdomains</key> <true/> </dict> </dict> </dict> !codebreak

Comments (13)
Tube
6 years ago
I must use VPN with U. S. IP address to avoid this message when loading mzstatic url: "Not Found on Accelerator Description: Your request was not found. Check the location and try again."
Huo En Ci
6 years ago
in the heightForHeaderInSection, you can do return self.podcasts.count == 0 ? 250 : 0
Sean Sneed
6 years ago
This could just be me (most likely) but this resulted in a black screen. steps to duplicate result: type "npr" and press Search click on tabbar button item "Favorites" then click back on tabbar button item "Search"
Huo En Ci
6 years ago
try putting this line of code in your setupSearchController function: definesPresentationContext = true
Aurélien Haie
5 years ago
Wow, i didn't notice that black screen appearing when toggling tabbar items ! Thanks for remarking it Sean Sneed And thanks Huo En Ci, it finally works fine for me with this boolean :)
Raph
6 years ago
Hi Brian, Any reason why you chose this framework rather than AlamofireImage?
Brian Voong
6 years ago
Tokyojogo
6 years ago
Hi Brian, for a production app, is SDWebImage really being used? Or are we expected to create our own way of caching?
ayon
6 years ago
I have used alamofireImage before, but I didnt find any difference between sdImage or alamofireImage, i think at the end of the day it's more or less about what one prefers to work with.
Brian Voong
6 years ago
Bashir SK
6 years ago
How do you make teaching this so easy. I have been learning swift and iOS for a year and just found about you. I'm glad i did. I have been stumbling through networking thinking it's very difficult and learning other topics. i have to say the way you teach it looks easy to learn and grasp easily. Thank you for your knowledge Brian, i'm hoping for my project type apps like this. Cheers
Brian Voong
6 years ago
Bashir SK
6 years ago
Very true. Cheers
Alpensol
6 years ago
Hey Brian, why did you decide on using an external framework instead of using something like NSCache or writing a small utility class for storing data in the file system or Core Data ?
Brian Voong
6 years ago
johnrm9
6 years ago
SDWebImage framework compiler warnings: I love clean compiles without warning messages. There is a way to eliminate the Block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior from the SDWebImage. Go to StackOverflow -> https://stackoverflow.com/questions/21577711/block-implicitly-retains-self-explicitly-mention-self-to-indicate-this-is-i See Solution for CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = NO.
Brian Voong
6 years ago
juliolocoh
5 years ago
Brian when you go to ApiService instead of podcast this line let parameters = ["term":searchText, "media": "music"] I used music it download music but the pictures of artists didn't show up in the cells how to fix it?
spohle
5 years ago
really great course brian and very helpful. could we get some kinda pop out player window or similar? the 2 side bars take up space so i have to make the browser window relative large in order to get a decent size for the video to see the code. something where the video can take up the whole space would really help. thanks
Brian Voong
5 years ago
spohle
5 years ago
thanks. appreciate it
mattbecker7
5 years ago
Hey Brian, I am getting weird results with the images being downloaded. the images are showing up duplicated. Your head shot image is showing up under random podcast posts. I am using SDWebImage like you showed, it seems like its a caching problem like we had before on the Instagram course. Any thoughts? thanks, Matt
Brian Voong
5 years ago
mattbecker7
5 years ago
Ok got it! thanks, I guess some of the images are not available so I get just white box. but it's working fine now.
mattbecker7
5 years ago
Update, I changed the image url to pull artworkUrl100 and it loads all the images now. No more blank white backgrounds. If I use artworkUrl600 and then just try and print the url in console it shows nothing for about 90 percent of searches. not sure why, maybe need to use async with completion somewhere. thanks
gottaminute
5 years ago
Hello Brian, I'm using this course to help in my own implementation so I'm not following step by step, but the issue I'm having is the images only show if I tap a row. On initial load the TableView show the cell.textLabel and cell.detailTextLabel, but only shows the imageView if I click or tab a row. What would cause this? Here is my code: let url = URL(string: course.url ?? "") URLSession.shared.dataTask(with: url!) { (data, _, _) in print("finished loading data:", data) DispatchQueue.main.async { cell.imageView?.image = UIImage(data: data!) } }.resume() cell.textLabel?.text = course.title cell.detailTextLabel?.text = String(course.link) return cell Thanks for you help!!
Brian Voong
5 years ago
gottaminute
5 years ago
Thanks for the response! I did use SDWebImage after I posted this question, but it does the same thing. So by creating a custom cell you mean create a coca file using a custom .xib? I haven't done that yet, but if that's what would work best I will give it a shot. Do you have a video that goes over that?
Brian Voong
5 years ago
Amir Nickroo
5 years ago
[AmiraclePodcast.Podcast(trackName: Optional("Lets Build That App"), artistName: Optional("Brian Voong"), artworkUrl1600: nil, trackCount: Optional(3), feedUrl: Optional("https://feeds.soundcloud.com/users/soundcloud:users:114798578/sounds.rss"))] I am getting a nil value when pulling the data for the artworkUrl1600..any suggestions?
njdavis
4 years ago
Hey Brian, When I search for a podcast the text "Please Enter Search Term" does not go away. Is this supposed to happen?
njdavis
4 years ago
Nevermind, just watched the next episode
plegmasena
4 years ago
Hai All, I haven't jump into the next video, but in case you're experiencing a blank page issues on Search Page like me, I've found a solutions. Step to reproduce: 1. Run our project on simulator / on devices. 2. Type any text on Search fields, do not tap Cancel button. 3. Move to another page (let say Favorites page) and than go back to Search page, you'll see that the Search page becomes blank. To solve that issue, I just added definesPresentationContext and set it to true, at the setupTableView function. -- Here's the code snippet: ------------------------------------ // PodcastSearchController.swift ------------------------------------ ... fileprivate func setupTableView() { tableView.tableFooterView = UIView() let nib = UINib(nibName: "PodcastCell", bundle: nil) tableView.register(nib, forCellReuseIdentifier: cellId) self.definesPresentationContext = true } ... I hope the solution is work for you also. But again, probably on the other video, Brian already have the solutions. Will check it out soon. Thanks,
DiegoOruna
4 years ago
Error quite difficult to debug. Thank you!
HELP & SUPPORT