Save and cache images in a SwiftUI app | Continued Learning #27
Vložit
- čas přidán 29. 04. 2021
- In this video we will implement a simple NSCache to temporarily save an image. Caching is a very common technique used in all software development (not just iOS Development) where we can take objects that we've downloaded from the internet and temporarily store them somewhere for reuse. This is help us avoid having to re-download the objects if they appear on the screen a second time. This is quite similar to the last video in this series, except the FileManager is for more permanent objects that will save to the device forever, while NSCache is for temporary objects that will only save for the current session.
In the next video in this series, we develop a real application that efficiently utilizes an NSCache for downloading images!
Next video: • Download and save imag...
Last video: • Save data and images t...
🤙 WELCOME BACK 🤙
WEBSITE: www.swiftful-thinking.com
DISCORD: / discord
GITHUB: github.com/SwiftfulThinking/
SAY THANKS: www.buymeacoffee.com/nicksarno
I have done all 26 parts of SwiftUI Continued Learning and must say it was an excellent structured and high-quality course. everything worked without hiccups technically. Recommend Nick and his teaching style. #27 is a must :) Best one in this course. Thanks :)
This modification will delete the cache when you click on the button.
func removeFromCache() {
infoMessage = manager.remove(name: imageName)
cachedImage = nil
}
Great video!
Thank you for such great content . Will there be content on algorithms and their comparison depending on randomness ?
Thanks for sharing video~~
Amazing~~
Thank you , i implement this idea in my project
Swift UI God❤️😎
thanks again happy to have done all
You are a machine! haha
Thanks Nick
Thanks as always Charlie!
Great video man! Would love to know that keyboard you're using, satisfying as hell
This was 2019 MacBook Pro before they changed the keyboard 😰
@@SwiftfulThinking ugh the good old days haha thanks man for all your videos. Sincerely appreciate the content
Thank you so much Nick. I have a question, is this computed property: "var imageCache: NSCache = { }()" the same as this one:" var imageCache: NSCache { }" ? Or what is the difference?
We use the () to call the initializer to actually create the object
Catching .... LOL Takes me back to Type-Allie-Us .... LOOLLLLL
lol indices
@@andrewli1455 Well you could always Catch in Dices...but what would you have?😁
but how can I save images in directory?I mean to show saved images when I re open the app
Thank you so much, Nick. I have a question. For getFromCache(), due to returnedImage, it does not work properly. When I pressed save, get and remove buttons in order, the image from the cache remains on the screen.
Chuljin, this is because of your getFromCache(). When you added the “if let” to safely unwrap the optional, you got rid of the nil.
So, instead of “cacheImage” = nil, it will still = the last image.
If Nick were to try to remove the image from the canvas again at the end of the video, it wouldn’t work for him either.
If you want to have same effect, set cachedImage to nil like so
…} else {
cachedImage = nil
infoMessage = “Not found in cache”
}
Modify the getFromCache else class to set cachedImage back to nil. Then when you get the image again and it is not found, the UI will remove the image from the screen.
Hello Nick, you said that there are third party libraries that will cache much more efficiently. Which one would you recommend?
I’m gunna make videos on these soon, but in order:
1. SDWebImageSwiftUI
2. Kingfisher
3. NukeUI
Thank you very much, best content creator like always!@@SwiftfulThinking
The fact that you kept calling it catch instead of cash is odd hahahaha