Save and cache images in a SwiftUI app | Continued Learning #27

Sdílet
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

Komentáře • 29

  • @tomb.6995
    @tomb.6995 Před rokem +5

    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 :)

  • @josephestrada4222
    @josephestrada4222 Před 3 měsíci +1

    This modification will delete the cache when you click on the button.
    func removeFromCache() {
    infoMessage = manager.remove(name: imageName)
    cachedImage = nil
    }

  • @zahscr
    @zahscr Před 9 měsíci

    Great video!

  • @hashcat5721
    @hashcat5721 Před rokem +1

    Thank you for such great content . Will there be content on algorithms and their comparison depending on randomness ?

  • @user-eg7ep8db8j
    @user-eg7ep8db8j Před 2 lety +1

    Thanks for sharing video~~
    Amazing~~

  • @heshamabdo6024
    @heshamabdo6024 Před rokem

    Thank you , i implement this idea in my project

  • @kdtechniquesofficial6153
    @kdtechniquesofficial6153 Před 2 lety +3

    Swift UI God❤️😎

  • @mig12394
    @mig12394 Před 3 lety

    thanks again happy to have done all

  • @Nunny25
    @Nunny25 Před 2 lety

    Thanks Nick

  • @jimmyciaston7733
    @jimmyciaston7733 Před rokem

    Great video man! Would love to know that keyboard you're using, satisfying as hell

    • @SwiftfulThinking
      @SwiftfulThinking  Před rokem

      This was 2019 MacBook Pro before they changed the keyboard 😰

    • @jimmyciaston7733
      @jimmyciaston7733 Před rokem

      @@SwiftfulThinking ugh the good old days haha thanks man for all your videos. Sincerely appreciate the content

  • @andresraigoza2082
    @andresraigoza2082 Před 2 lety +1

    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?

    • @SwiftfulThinking
      @SwiftfulThinking  Před 2 lety +1

      We use the () to call the initializer to actually create the object

  • @comics-on
    @comics-on Před 2 lety +2

    Catching .... LOL Takes me back to Type-Allie-Us .... LOOLLLLL

    • @andrewli1455
      @andrewli1455 Před rokem +1

      lol indices

    • @kenturnbull9679
      @kenturnbull9679 Před rokem

      @@andrewli1455 Well you could always Catch in Dices...but what would you have?😁

  • @ciaociccio5389
    @ciaociccio5389 Před 2 lety

    but how can I save images in directory?I mean to show saved images when I re open the app

  • @chuljinhwang8386
    @chuljinhwang8386 Před 2 lety

    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.

    • @dre5671
      @dre5671 Před rokem +1

      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”
      }

    • @1slyboy
      @1slyboy Před 9 měsíci

      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.

  • @kevincosta2132
    @kevincosta2132 Před 5 měsíci

    Hello Nick, you said that there are third party libraries that will cache much more efficiently. Which one would you recommend?

    • @SwiftfulThinking
      @SwiftfulThinking  Před 5 měsíci +2

      I’m gunna make videos on these soon, but in order:
      1. SDWebImageSwiftUI
      2. Kingfisher
      3. NukeUI

    • @kevincosta2132
      @kevincosta2132 Před 5 měsíci

      Thank you very much, best content creator like always!@@SwiftfulThinking

  • @noamif
    @noamif Před 2 lety +2

    The fact that you kept calling it catch instead of cash is odd hahahaha