Swift: Loading Images Asynchronously and storing with NSCache and NSURLCache

  Рет қаралды 40,388

Lets Build That App

Lets Build That App

Күн бұрын

Пікірлер: 122
@ParthAnand
@ParthAnand 8 жыл бұрын
you are the best! this is an understatement for you. please never stop making tutorials.
@locacocavola
@locacocavola 8 жыл бұрын
I love the way you implemented the activityIndicatorView on each StatusImageView. Again, thanks for what you're doing. Happy Sunday.
@LetsBuildThatApp
@LetsBuildThatApp 8 жыл бұрын
Thanks Andrea, going the extra mile to demonstrate a concept goes a long way.
@TheKaushal8686
@TheKaushal8686 8 жыл бұрын
Your way of explaining things is way super than others.... thanks for yet another amazing video....
@samuelpmilanez
@samuelpmilanez 4 жыл бұрын
And before i forget, congratulations! Your videos are amazing !
@shivamroy1775
@shivamroy1775 8 жыл бұрын
You are awesome . I actually learn everything in so detail in your channel . You're great .
@LetsBuildThatApp
@LetsBuildThatApp 8 жыл бұрын
Glad to help you on your coding journey Shivam
@pasib
@pasib 8 жыл бұрын
Once again an excellent tutorial! This one saved me a lot of time. Thank you Brian!
@LetsBuildThatApp
@LetsBuildThatApp 8 жыл бұрын
Can I get a cup of coffee with the time saved?
@yogitamunde6134
@yogitamunde6134 7 жыл бұрын
Nice tutorial.all cache basic is covered ,,,Really helpful...
@LetsBuildThatApp
@LetsBuildThatApp 7 жыл бұрын
Indeed, however there is much more about caching that I wish to go over in later videos.
@abhisheksitar
@abhisheksitar 8 жыл бұрын
Amazing tutorials , learnt a lot of stuff and made me a better programmer. Thank you.
@akzuki1210
@akzuki1210 8 жыл бұрын
This is amazing. Thanks a lot. Waiting for more tutorials
@LetsBuildThatApp
@LetsBuildThatApp 8 жыл бұрын
Thanks, I like your haircut!
@TheYannsonnboys
@TheYannsonnboys 8 жыл бұрын
Your tutorials are amazing man. Thanks for that
@LetsBuildThatApp
@LetsBuildThatApp 8 жыл бұрын
+Yannsonnboys Yannick Great to be of service to you.
@SteveWoznokav
@SteveWoznokav 7 жыл бұрын
Hi Brian can you please make another video on how to properly clear the cache when it is full using different methods?
@infohpreet
@infohpreet 2 жыл бұрын
Great tutorial!! Thanks!!!
@art4ho
@art4ho 6 жыл бұрын
Thanks again for your sharing!!! Really hero
@csrkn
@csrkn 7 жыл бұрын
Thank you so much man. You really helped me a lot. Please keep up the great work!
@VivekVerma1993
@VivekVerma1993 8 жыл бұрын
Is it possible to make image height dynamic in the cell, as you have done with status textview. PS: when you have url of that image(dynamic content)
@michaelkornelakis8507
@michaelkornelakis8507 8 жыл бұрын
Man you are amazing! Thanks once again!
@megaman9422
@megaman9422 5 жыл бұрын
there's something missing between this video and the one before it, in the one before it you didn't have FeedCell file and image url was not yet set up.
@rameshannadurai4523
@rameshannadurai4523 6 жыл бұрын
Excellent tutorials. How did you add ActivityIndicatorView to FeedCell while downloading the image. It is not explained in this video, Is it in different video?
@samuelpmilanez
@samuelpmilanez 4 жыл бұрын
What the better way? Use the default cache provided by NSURLSession or use my own cache maked using NSCache class? If i use NSURLSession and implement a cache using NSCache, therefore some images are cached twice? (NSURLSession and my NSCache object)
@haleemmilk
@haleemmilk 8 жыл бұрын
You are amazing thanks alot for sharing your knowledge
@david-tracy
@david-tracy 6 жыл бұрын
Great work
@pankajchauhan9185
@pankajchauhan9185 5 жыл бұрын
Hey, Brain I have a tableViewCell in which I am getting dynamic image size according to which I have to calculate image height but while using this code for getting image height. let imageURL = URL(string: strImageUrlPath) var imageData: Data? if imageData == nil { if let imageURL = imageURL { imageData = Data(contentsOf: imageURL) } } var img: UIImage? = nil if let imageData = imageData { img = UIImage(data: imageData) } scrolling of table view got stuck or some times zerk while scrolling . please give me some solution for that.
@AnuragKashyap17
@AnuragKashyap17 7 жыл бұрын
Great Tutorial :D Thank you for this :) keep up the good work.
@aragorn392
@aragorn392 7 жыл бұрын
Thanks! Is there any reason you used a dataTask vs a downloadTask? Wouldn't you want to use a downloadTask for images?
@thanasistratigakis9360
@thanasistratigakis9360 8 жыл бұрын
Great tutorials! Subscribed
@LetsBuildThatApp
@LetsBuildThatApp 8 жыл бұрын
+Thanasi Stratigakis thanks a lot, lots more coming!
@abhinaykumar1045
@abhinaykumar1045 6 жыл бұрын
Hi Brian, Hope you are doing good. Such a nice tutorial. I have a question when should I use this tutorial method and when should I use third party lib like AFNetworking etc. Thanks in advance:)
@EvaristusEzekwem
@EvaristusEzekwem 7 жыл бұрын
Awesome tutorials I must say Brian. You have influenced a lot of my coding style thanks a loooooooooooot. There's actually a gap between this video and the previous one. Some files (e.g Posts.swift, Extensions.swift, FeedCell.swift) weren't in the previous video. I have tried to recreate these files myself but I keep running into errors from the FeedCell.swift file. Please help. Thanks.
@shivakumarhiremath8013
@shivakumarhiremath8013 5 жыл бұрын
Hi .. I am big fan your turorials..in this video you said how to use Nsurlsache ,can you tell us how to clear or reset the Nsurlcache when Nsurlcache becomes full
@johnhan800
@johnhan800 8 жыл бұрын
Excellent tutorial! Thank you so much, for saving my homework!! lol
@laujimmy9282
@laujimmy9282 6 жыл бұрын
Thx for the great tutorial
@Somerandomname23
@Somerandomname23 8 жыл бұрын
Hi, it's also work, when I disappear this view, and back to him? whether will be download again? I mean in NSURLCache way.
@Zakawaka45
@Zakawaka45 8 жыл бұрын
Great video! But i have to ask, how did you learn about caching in swift, theres barely anything about it online
@david-tracy
@david-tracy 6 жыл бұрын
Would you need to change anything in case you were getting dynamic data? (some data may not be there anymore, new posts added)
@nicholaslue
@nicholaslue 8 жыл бұрын
I'm tying to figure out how to do this with videos. I'm guessing it's different because the action to play the video calls the URL everytime.
@LetsBuildThatApp
@LetsBuildThatApp 8 жыл бұрын
Hello Nicholas. You should be able to perform similar caching if you can get access to the downloaded video file. I've never had to handle this but I'd be surprised if this issue hasn't been solved on StackOverflow.
@MohitJain14
@MohitJain14 8 жыл бұрын
Great! Thank you.
@dillionwang5863
@dillionwang5863 7 жыл бұрын
Good lesson! Veay helpful
@AlessandroArcidiaco
@AlessandroArcidiaco 8 жыл бұрын
Hi Brian, thank you for this amazing tutorial. One question: the images remains in cache when the app is in background mode?
@raymondong4504
@raymondong4504 6 жыл бұрын
Thanks for putting this together. Really helpful stuff for getting me started with ios dev. Really interested with the paid lessons on your site. Just a question though. There seems to be missing video in this series; factoring out the data and code for the loader and server calls. Tried searching from your list but couldn't find it. Thanks so much.
@LetsBuildThatApp
@LetsBuildThatApp 6 жыл бұрын
Not sure if I actually show how to refactor the code. It's just simple practice to clean up projects after a while.
@thinkoreans
@thinkoreans 8 жыл бұрын
Thanks for another great tutorial. I'm quite new to Swift but I see your way of set things up programmatically is somehow more organized and easier to see the whole picture. But I'm still on two minds whether I code my project without storyboard because I'm afraid I can't find good lessons on the internet when I hit a bump in the road. As you know, almost all the lessons use storyboard and your way is quite special. Can you suggest me any advice on this? What can be the best way to improve my coding or solve any issue when I do it programmatically?
@LetsBuildThatApp
@LetsBuildThatApp 8 жыл бұрын
Like you mentioned above, doing things programmatically is more organized and easier to follow what is going on. Here's a statement that usually holds true: If you know how to do something in code, you will most likely know or will be able to figure out how to do it in a storyboard. I can't say that the inverse holds true. Also the major difference for me is that while I can use storyboards for a lot of projects, I can use the programmatic approach for all projects.
@PanagiotisGoutzianas
@PanagiotisGoutzianas 7 жыл бұрын
Hi can i ask something?What happens if there is no internet connection , can someone see the images that were cached before?
@dopors
@dopors 4 жыл бұрын
Will this method also being use by WKWebView? let say i have a video intro(intro1.mp4) and of course within the WKWebView you are sending request(using interceptor(URLProtocol) you can browse each request within). If not are there any caching method that you can use for faster loading video?
@LetsBuildThatApp
@LetsBuildThatApp 4 жыл бұрын
Yes, don't use WKWebView.
@CaffieneToCode
@CaffieneToCode 7 жыл бұрын
You are a champ Brian! Your continuous efforts in making people understand things practically are much appreciated. I tried the way of caching that you explained in KZbin app. Somehow it doesn't work. Is there a change in implementation for swift 3/4?
@LetsBuildThatApp
@LetsBuildThatApp 7 жыл бұрын
I would recommend looking at my cache implementation from LBTAComponents or browsing the source code for SDWebImage.
@guduruvamshikrishna7355
@guduruvamshikrishna7355 7 жыл бұрын
Finished project with Latest Swift syntax here: github.com/VamshiIITBHU14/FBClone
@aboutcarsyo
@aboutcarsyo 7 жыл бұрын
Do you think the best way to link the tableView data to the imageViews etc. is with the didSet inside the custom cell class like you did here? I'm just asking because I used to link it in cellForRowAtIndexPath and since this video is a little older by now, maybe you found another way you would consider as better? If not I will change my code and also use didSet inside the cell class :) Thanks for you great videos, I learned a lot from you!
@LetsBuildThatApp
@LetsBuildThatApp 7 жыл бұрын
It is best to keep your controllers really simple and not have them be aware of how cells are rendered. This way you implement separation of concern for your classes.
@aboutcarsyo
@aboutcarsyo 7 жыл бұрын
Okay thanks a lot for your answer :) also performance wise it should be pretty good? Cause I had some problems with the scrolling sometimes it was a little choppy, just very little but noticeable
@joaquincorrales7383
@joaquincorrales7383 8 жыл бұрын
Brian, thank you so much for the great tutorials. I have a question- would you have any idea why the scrolling in the collectionview seems very choppy even caching the images? Thanks
@LetsBuildThatApp
@LetsBuildThatApp 8 жыл бұрын
Hi Joaquin, it could be your simulator that is choppy. Also, make sure you are storing the UIImage in the cache, also make sure the cache is actually getting back your uiimage objects instead of making another url request.
@joaquincorrales7383
@joaquincorrales7383 8 жыл бұрын
Lets Build That App Hey Brian thanks for the reply. I'm actually experiencing it on my phone as that's where I'm testing on. The images are being cached and not being fetched more than necessary. I have also tried upping the default cache. Any other pointers? Thanks a lot man. Huge fan
@billionbucks5391
@billionbucks5391 8 жыл бұрын
great job , best of luck man :)
@LetsBuildThatApp
@LetsBuildThatApp 8 жыл бұрын
+Billion Bucks thanks for watching!
@dzaev3663
@dzaev3663 8 жыл бұрын
You lecture is really awesome. I learn the depth of swift from you. Thank You so much. And I have a quesiton. What do you refer at the starting point? I mean, I proceed to study in the order of this "How to create Facebook's news feed" playlist, but maybe it's different between a completed source code of "Dynamic cell content" part and the code of this lecture at starting point. So what the other viewers refer? I wonder how to proceed, thank you.
@LetsBuildThatApp
@LetsBuildThatApp 8 жыл бұрын
Hello David, You should watch the entire FB tutorial series using this playlist: kzbin.info/aero/PL0dzCUj1L5JHDWIO3x4wePhD8G4d1Fa6N
@dzaev3663
@dzaev3663 8 жыл бұрын
Thanks for your reply, and I did refer the same playlist as you send me. But the source code is different, neither is the feed images. In the last part of "Dynamic cell content" lecture, the feed images is like DOG picture, JOBS picture seeing at 24:53. But in this lecture at start point, the feed images is totally different. Same in the source code.
@LetsBuildThatApp
@LetsBuildThatApp 8 жыл бұрын
Yes the code changes a bit. Apologies, I didn't intend for these episodes to be continuous. These videos were shot way way way back in feb/march, I was still getting used to presenting code while recording. From now on, I'll create continuous content that will be easy to follow.
@dzaev3663
@dzaev3663 8 жыл бұрын
I see. Thank you!!
@firstinline101
@firstinline101 7 жыл бұрын
Really enjoyed this tutorial, thought it was great/interesting. Do large companies like Instagram or Facebook that have a lot of content in the form of photos/videos use similar NSURLCache methods?
@LetsBuildThatApp
@LetsBuildThatApp 7 жыл бұрын
Photos are definitely cached using their own sophisticated library where items are evicted in a very efficient process. You gotta go to one of their talks to see what is really under the hood for their apps.
@firstinline101
@firstinline101 7 жыл бұрын
Ok, just wondering how translatable code is between smaller scale developers and the big boys! Thank you for your reply.
@david-tracy
@david-tracy 6 жыл бұрын
How can we find these talks?
@kylim7523
@kylim7523 6 жыл бұрын
setSharedUrlCache in Swift 4.2?
@GameCrawl
@GameCrawl 8 жыл бұрын
The library that you mentioned at the end is this github.com/rs/SDWebImage?
@daurenmuratov7
@daurenmuratov7 7 жыл бұрын
Awesome video! But, right now I'm having a problem. Every time collectionView bounces of the top, the first cell lags while going back to its position. Did Anyone have such problem?
@dany3370
@dany3370 6 жыл бұрын
11:38 swift 4 update: var imageCache = NSCache()
@abdallahsultan8797
@abdallahsultan8797 8 жыл бұрын
hiii,, what if i want to change the image without change the link..is that possible? if not>> can i load set of images (i will replace it weekly) from firebase to my app ? if not>> any solution plz??
@laiqueahmed6613
@laiqueahmed6613 7 жыл бұрын
Hi Brian thanx a lot for the video. But I have few questions 1. What is the size of default cache ? I saw in the above video 500KB image was fetching from network but 32KB image was in cache I guess it loaded faster. 2. Does AlamofireImage library takes care of caching ? 3. What is the maximum size I can define for cache ? you have set diskcapacity 500 * 1024 * 1024 ? How many MB's ?
@LetsBuildThatApp
@LetsBuildThatApp 7 жыл бұрын
You should read the documentation on NSCache.
@david-tracy
@david-tracy 6 жыл бұрын
Ahmed did u find out?
@joshivanilla
@joshivanilla 8 жыл бұрын
First of all thanks for the tutorial! I have a question: Currently I'm using Firebase to store and fetch image. But I am experiencing a problem where the image are in the wrong tableviewcell even though the image urls in each cell are correct. Google told me that it was because the image files are too large and images are being overwritten (something to deal with async as well) Are there any ways I can solve this?
@LetsBuildThatApp
@LetsBuildThatApp 8 жыл бұрын
I run into this quite often, and ran into this while using firebase as well. I'll address it with my solution in a Firebase tutorial soon. Thanks for watching.
@joshivanilla
@joshivanilla 8 жыл бұрын
+Lets Build That App Awesome! Subbed and thanks!
@OrkhanAlizade
@OrkhanAlizade 7 жыл бұрын
Thanks for he tutorial! But why there is a gap between this and previous video? In which part have you wrote that new code part???
@LetsBuildThatApp
@LetsBuildThatApp 7 жыл бұрын
+Orkhan Alizade Happy hunting my child
@OrkhanAlizade
@OrkhanAlizade 7 жыл бұрын
Lets Build That App excuse me?
@Abdi-uy1kh
@Abdi-uy1kh 7 жыл бұрын
haha that was random
@VictorAlves-ur7lp
@VictorAlves-ur7lp 8 жыл бұрын
very nice explanations , but you do not use the storyboard?
@LetsBuildThatApp
@LetsBuildThatApp 8 жыл бұрын
+Victor Alves I like typing everything in code, call me old school :)
@BrettCWX
@BrettCWX 8 жыл бұрын
Oldschool
@kongli886
@kongli886 8 жыл бұрын
Every time the application exits the cache is also cleared. How can I make the application not clear the cache once it exits? I don't want my app to load the images user once loaded every time the app is reopened. It's just like your web browser, your files are stored in a temporary folder until you delete the temporary files
@LetsBuildThatApp
@LetsBuildThatApp 8 жыл бұрын
The cache will not help you if you're trying to keep a persistent state of your files. I suggest looking into CoreData to store your files using a binary format. Another method is to store the files directly into your app.
@eyalby111
@eyalby111 8 жыл бұрын
Hi, I don't think there is a good video tutorial on using AlamofireImage. if you can make one (using all his features and explaining them) it will be great!
@caelandailey6438
@caelandailey6438 7 жыл бұрын
I have an issue. It'll set the cell's image to a previous cells image, and then switch it a fourth of a second later to the correct image. What am i doing wrong?
@LetsBuildThatApp
@LetsBuildThatApp 7 жыл бұрын
+Caelan Dailey probably cell recycle affecting your app
@krovogadniy
@krovogadniy 7 жыл бұрын
same problem. is there a solution?
@learning2886
@learning2886 8 жыл бұрын
Make a Udemy tutorial. Id buy it instantly. intermediate to advanced topics for the swift language is a soft market there and you're course would sell like fire. just sayin'... I spend 50$ a month on courses there.
@LetsBuildThatApp
@LetsBuildThatApp 8 жыл бұрын
+Hunter Walker Thank you for the info regarding udemy. With the pricing changes and strictness of that platform, I'd have to continue monitoring before I step into that world.
@janardhanmupparaju2940
@janardhanmupparaju2940 6 жыл бұрын
Hi, I am trying to load 100 or more images in tableview using SDWebImage but after downloaded all images getting Error Message from debugger: Terminated due to memory issue and after App is Crashing
@LetsBuildThatApp
@LetsBuildThatApp 6 жыл бұрын
Cool, check the memory usage of your app
@janardhanmupparaju2940
@janardhanmupparaju2940 6 жыл бұрын
thanks for your reply, now i identified problem is loading high resolution images in tableview
@LetsBuildThatApp
@LetsBuildThatApp 6 жыл бұрын
Yeah you'll bust the memory limit real quick with high res images.
@leanprogrammer
@leanprogrammer 7 жыл бұрын
(Min 6)Is it possible that there's no need to cache anymore(as of October 2017)? Because my images do not reload. It is as if the network request is made once and the image is automatically cached. Anyone experiencing the same thing? Thanks in advance
@LetsBuildThatApp
@LetsBuildThatApp 7 жыл бұрын
It all depends on how fast your internet connection is. Caching comes into play on 3g and much bigger apps.
@leanprogrammer
@leanprogrammer 7 жыл бұрын
Oh okay, thanks Brian
@nverabgaryan
@nverabgaryan 4 жыл бұрын
what about video preloading ?
@LetsBuildThatApp
@LetsBuildThatApp 4 жыл бұрын
I suggest using HLS for video playback speed improvements.
@pavanteja1996
@pavanteja1996 8 жыл бұрын
sir is it possible to link Facebook's news feed to this app
@LetsBuildThatApp
@LetsBuildThatApp 8 жыл бұрын
Hello Pavan. Unfortunately, Facebook does not allow developers to replicate behavior similar to their iOS app.
@locacocavola
@locacocavola 8 жыл бұрын
What about twitter?
@roark09
@roark09 8 жыл бұрын
Brian I'd like to ask if I can follow you on facebook or twitter.
@LetsBuildThatApp
@LetsBuildThatApp 8 жыл бұрын
Yes you can follow me on twitter at @buildthatapp
@tapizquent
@tapizquent 6 жыл бұрын
Why not compress the image instead of bumping the cache up?
@LetsBuildThatApp
@LetsBuildThatApp 6 жыл бұрын
Why not both?
@david-tracy
@david-tracy 6 жыл бұрын
would we then need to decompress the image after grabbing it from the cache and presenting it to the collection view?
@tapizquent
@tapizquent 6 жыл бұрын
CDMusicGroup no, why would you? Since you’re displaying the imagine on the screen, you don’t need it to be a huge image. Just like Instagram, images are very low res cause you don’t need a huge image for a phone
@david-tracy
@david-tracy 6 жыл бұрын
Tapizquent ok, sounded like you were saying to compress it into a file of a different (similar to how a .zip is compressed). I’m now seeing you’re referring to resizing and reducing the resolution of the image. Am I understanding you better now or are we still not on the same page
@tapizquent
@tapizquent 6 жыл бұрын
CDMusicGroup you are right. I was just referring to saving a smaller image.
@pvane0123
@pvane0123 5 жыл бұрын
wasted 20 min... this is no longer applicable
Swift: Create Facebook's Tab Menu system with UITabBarController
23:45
Lets Build That App
Рет қаралды 59 М.
Swift: Facebook News Feed - Dynamic Cell Content
26:20
Lets Build That App
Рет қаралды 23 М.
Леон киллер и Оля Полякова 😹
00:42
Канал Смеха
Рет қаралды 4,1 МЛН
How Many Balloons To Make A Store Fly?
00:22
MrBeast
Рет қаралды 190 МЛН
Чистка воды совком от денег
00:32
FD Vasya
Рет қаралды 6 МЛН
Caching images
11:41
SwiftBook
Рет қаралды 7 М.
NSCache: Performant iOS App Basics (2022)
14:11
iOS Academy
Рет қаралды 14 М.
API Caching with Combine
25:46
Kelvin Fok
Рет қаралды 1,3 М.
How to Upload Your App to TestFlight | Swift Xcode
6:25
Jason Dubon
Рет қаралды 29 М.
Downloading & Caching Images in iOS with Swift
27:49
Sam Meech-Ward
Рет қаралды 11 М.
Swift Algorithms - Faster, Cleaner Code. (Chunked Example)
13:48
PhotosPicker - SwiftUI
21:39
Stewart Lynch
Рет қаралды 7 М.
Parsing JSON Just Became Super Easy in Swift 4 with Decodable
19:30
Lets Build That App
Рет қаралды 274 М.
Леон киллер и Оля Полякова 😹
00:42
Канал Смеха
Рет қаралды 4,1 МЛН