Download and save images using FileManager and NSCache | Continued Learning #28

Sdílet
Vložit
  • čas přidán 26. 08. 2024
  • Woohoo! I'm so excited to share this video because we get to use many of the concepts that I've covered in the past 5-10 videos and put them to use. In this video, we will create a "mini app" within our project. We will use MVVM (Model-View-ViewModel) architecture to set up our app and then add some extra "Utility" classes to incorporate additional classes.
    Links within this video:
    - URL for API: jsonplaceholde...
    - URL for 1st Image: via.placeholde...
    Prerequisites for this video:
    - Background Threads: • Multi-threading with b...
    - Weak Self: • How to use weak self i...
    - Codable: • Codable, Decodable, an...
    - Combine: • Download JSON from API...
    - Publishers / Subscribers: • Publishers and Subscri...
    - FileManager: • Save data and images t...
    - NSCache: • Save and cache images ...
    🤙 WELCOME BACK 🤙
    WEBSITE: www.swiftful-t...
    DISCORD: / discord
    GITHUB: github.com/Swi...
    SAY THANKS: www.buymeacoff...

Komentáře • 101

  • @amith2947
    @amith2947 Před 3 lety +16

    mate you are the best, there is no teacher like u. we need people like you in this world. you got a lifetime loyal subscriber. keep doing what you are doing.
    thank you soo much.

  • @udonthavasoul
    @udonthavasoul Před 2 lety +4

    I followed all the tutorials thus far, coded the app in this video 4 times... I think I'm ready for the next lesson. Thank you

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

    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.

  • @MosabbirSadman
    @MosabbirSadman Před rokem +2

    Thank you so much for this Nick! You are helping out the community to an extent you cannot even imagine! ❤

  • @Dois-
    @Dois- Před 2 lety +1

    I can't describe how much did I learn from this playlist. Thank you Nick!

  • @jp_0
    @jp_0 Před rokem

    Dear, Nick: I feel in debt with you. Thank you for putting so much time in delivering such a quality training for us. I don't know what else to say. God bless you.

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

    Whew! Great course Nick! Looking forward to diving into the next lessons!

  • @NoName-yg7te
    @NoName-yg7te Před 2 lety

    Thank you, Nick, so much. Cannot show how much I do appreciate your help.
    Your fan from Uzbekistan!

  • @chandan589
    @chandan589 Před 3 lety +1

    What can be better than this explanation while choosing cache and file manager!!! Great content which I must say man!!! Please keep continuing the same. :)

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

    I just finished watching this playlist. Learned so many new things. Very useful for my app that I’m currently working on. Thank you so much nick. You’re an awesome human being.. Love you brother.❤️😘

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

    Hey nick what a piece of art thanks for teaching me all this valuable stuff, you are badass. God bless you

  • @Sfstboy
    @Sfstboy Před rokem

    Best wholistic SwiftUI tutorial

  • @manfredkernMK
    @manfredkernMK Před rokem +1

    I made it thru the beginners and intermediates series. Easy to follow and I could also apply some tipps to my own small (MacOS) apps. Thank you so much for your work. 👍👍👍

  • @Nunny25
    @Nunny25 Před 2 lety

    Hi Nick, I finally went through this video. I spent several hours with him to understand everything. My way of thinking and programming is definitely changing. Thank you and see you at the next video :-)

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

    Great of knowledge you’re blessing us with! Thank you.

  • @olepetersen4460
    @olepetersen4460 Před 3 lety

    This is good. I mean really good! You provide structure, clarity and a great set of tools. I have watched and recoded most of your videos just to get the hang of this. I learn a lot. Thank you again for your insight and friendly and thorough lectures!

    • @SwiftfulThinking
      @SwiftfulThinking  Před 2 lety

      Thanks for watching Ole! I've seen you comment on a few videos now and it seems like you're progressing 😄

  • @AZMerf
    @AZMerf Před 3 lety +1

    Great video and teaching. I am so excited to have debugged my first SwiftUI app. I forgot to put the ! in front of the FileManager folder check. Took me an hour and I cheated by rewatching some of the video but I knew where to look and immediately figured it out when I stepped through it. I even added some logging and debug statements. Thanks for all your help.

    • @SwiftfulThinking
      @SwiftfulThinking  Před 3 lety

      Ahhh good catch. Yea sometimes printing to debug is the best route!

  • @sols.2525
    @sols.2525 Před 3 lety +1

    Amazing stuff. Thanks so much Nick. I love your teaching style and can't wait for your next series of videos!

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

      Thanks Scott! I'm almost done with the next playlist :)

    • @sols.2525
      @sols.2525 Před 3 lety

      @@SwiftfulThinking awesome, can't wait!

  • @Kevalkorat
    @Kevalkorat Před 2 lety

    Dude, your videos are really great and in-depth and covers so many edge cases for newcomers like me. Thanks for the great content and please don't stop what you are doing.

    • @SwiftfulThinking
      @SwiftfulThinking  Před 2 lety

      Hi Keval! Haha I'm glad you like them. More videos coming soon don't worry 🤓

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

    Hey nick I really want to become iOS Developer because a colleague from my company inspired me learn Swift and I am watching all your videos in order to study, you are awesome..

  • @hamzasipraa744
    @hamzasipraa744 Před 3 měsíci

    thanks you ❤..you are hardworking and you are a good teacher...❤

  • @bobbynwm
    @bobbynwm Před rokem

    Excellent video Nick! Thanks a lot!

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

    One suggestion, is don't forget to delete the folder created by the simulator when done so that the files don't take up your HD space. 🙂

  • @mithunmadhav8716
    @mithunmadhav8716 Před 10 měsíci

    Great tutorial. A major caveat is that, with the NSCache implementation, if we put the app in the background and the cache evicts everything. So you can see all the images being downloaded again. Came here searching for the solution for this, but my search continues

  • @samarghourab5545
    @samarghourab5545 Před 2 lety

    Thank you Nick! This course was very helpful.

  • @yasseraltamimi6171
    @yasseraltamimi6171 Před 2 lety

    Hey Nick, I really can't thank you enough for what you're doing in these courses. I've Watched all the SwiftUI Bootcamp series and this series as well and every video I fell I'm learning something very important. Thank you again and I would love if there was a way to support this channel through Patreon or something like that.
    Thanks again!

  • @dre5671
    @dre5671 Před rokem

    Dang bro, you're amazing haha Can't get enough of your content.
    Currently prepping for a take home proj, and if it goes well, I owe you a beer!

  • @Seepho
    @Seepho Před 2 lety

    YOU ARE AWESOME! THANK YOU SO MUCH!!!

  • @lotpb
    @lotpb Před 3 lety +1

    Keep them coming Nick, did you go into a slumber LOLLLL

    • @SwiftfulThinking
      @SwiftfulThinking  Před 3 lety +3

      😂 Hahaha I'm hibernating! No I've actually been working on the next playlist that should be coming out this week!! We're going to build a whole app together, so I wanted to record all of the videos beforehand since they are all connected... I was going to send an update to my CZcams community but unfortunately I need 1,000 subscribers before I can use that feature lol 😩

  • @dugrut1325
    @dugrut1325 Před 2 lety

    I learnt, loved it, a great teacher!

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

    great tutorial - thank you!

  • @emdutt4012
    @emdutt4012 Před rokem

    if you know about async image you can use async image to download those images in a convenient way.

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

    Thank you for your videos!
    When will you publish new one?
    Can't wait)

    • @SwiftfulThinking
      @SwiftfulThinking  Před 3 lety

      Haha thanks for watching mkpwnz! I just finished editing my next course and will post it this week :) 25+ videos 🥳

  • @tbg6nb
    @tbg6nb Před rokem

    superb video, very informative ! please remove background noise if possible, it was not that loud in the first hour but became especially audible starting at 1:03:00

    • @chrisstromberg6527
      @chrisstromberg6527 Před rokem

      I couldn’t hear any background noise, I’m guessing it was noise in your background!

    • @tbg6nb
      @tbg6nb Před rokem

      ​@@chrisstromberg6527 no, I checked it now as well on both laptop and mobile phone and there is clearly audible white noise. As a music producer I am probably more aware of this than other people though...so I understand if some people don't notice this...

  • @alexeylobankov
    @alexeylobankov Před 2 lety

    Thanks for your content. Keep it going!

  • @TechRagh
    @TechRagh Před 3 lety +1

    Thank you Nick 🤩

  • @alooshman
    @alooshman Před 17 dny

    how is it that we're only downloading images for the rows on the screen? why isn't it downloading all the images even for the rows that are off screen? asking because im assuming the data, such as title, has already been downloaded and set for all rows, even those off screen.

  • @mig12394
    @mig12394 Před 3 lety

    very impressive demonstration !

  • @williamwildsmith5162
    @williamwildsmith5162 Před 2 lety

    Great Nick, however my teeny weeny brain struggles to get a good understanding of it all. Going to watch it 10 times - 9 to go!

  • @jpcg007
    @jpcg007 Před 2 lety

    Excellent tutorial!!!

  • @lizakryshkovskaya7412

    Thank you! 😍😍😍

  • @andresraigoza2082
    @andresraigoza2082 Před 2 lety

    This is great!!! Thank you so much

  • @chrisstromberg6527
    @chrisstromberg6527 Před rokem

    Another phenomenal video on SwiftUI, well done. I had to watch this video about three times, it makes sense now and it answers many questions I had. Do you know if AsyncImage utilizes the cache directory? I see some discussion where users state that it does cache images, yet the documentation does not state this.

    • @SwiftfulThinking
      @SwiftfulThinking  Před rokem

      I believe AsyncImage caches part of the http request but not the image itself. Honestly I’m not super familiar with it, since I don’t use AsyncImage in production. I’ve been using Nuke SDK which has highly customizable caching behavior.

  • @dugrut1325
    @dugrut1325 Před 2 lety

    HELP! The key is different for the Cache and the FileManager. The Filemanager is expecting the image name + .png not a imageKey which is 1, 2, 3 etc.
    I'm referring to the PhotoModelFileManger: private func getImagePath where it return folder.appendingPathComponent(key = ".png"). Here this key value is displayed as the .id Int value and not the imageName. How can this be fixed?????

  • @dugrut1325
    @dugrut1325 Před 2 lety

    I'll leave my bottom HELP messages, because maybe it will help someone else. In the PhotModelFileManager when we are checking to see if folder doesn't exist, well I didn't put in the ! [not]:
    if !FileManger.default.fileExists(atPath: url.path),
    it took awhile to spot it but I was persistent. I did what you said, I went through every file and made comments on each one with comments for each function. To see your logic. It makes the models very robust. As you're talking it is all very overwhelming but when I look back at the code and type out the explanation above each items it seems to make sense. I will will never be able to write code from route like you, I'll just have to steal it from your lessons. Anyway it's a start.

  • @oleg991
    @oleg991 Před rokem

    Hi, Nick! The video is great! Could you explain why you decided to use FileManager? Caching works with a single "var cache" property.

    • @SwiftfulThinking
      @SwiftfulThinking  Před rokem

      A "var cache" would save it to memory, which does not persist across app launches. If you restart the app, the "var cache" will reset, where the FileManager will save

    • @oleg991
      @oleg991 Před rokem

      @@SwiftfulThinking Oh well, this is true of course. Maybe I did not get the point of caching images? We use cache not to persist images after app relaunch but to avoid downloading duplicates multiple times in one working session. Am I right?)
      I watched the last part of the video and found an answer for my question.
      You basically gave two examples of saving images (cache and filemanager), they are different and should be used in different cases 👌

  • @wandahu8058
    @wandahu8058 Před rokem

    Good!

  • @AlexanderFarber
    @AlexanderFarber Před 3 lety

    Hi Nick, your tutorial is awesome. Please consider extending your app to store the downloaded JSON objects in Core Data?

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

      Hi Alexander! This isa great comment. The code is essentially the same as we did here, except instead of getting the image data, you save JSON data. This might help: programmingwithswift.com/how-to-save-json-to-file-with-swift/

  • @rwilson1125
    @rwilson1125 Před 2 lety

    aside from me typing poorly, i enjoy following along on these videos. I am half way through this one and it runs but does not show the list of images. the error is " I am presuming this is networks issues but I can see the the page with the list of images. the simulator fails similarly. Is there a setting hidden somewhere that is stopping this from working?

    • @SwiftfulThinking
      @SwiftfulThinking  Před 2 lety

      What error are u getting?

    • @rwilson1125
      @rwilson1125 Před 2 lety

      @@SwiftfulThinking Arggghhh. cut and pasta failure:::

    • @rwilson1125
      @rwilson1125 Před 2 lety

      @@SwiftfulThinking The data couldn't be read because it is missing.

  • @stolenhen
    @stolenhen Před 3 lety +1

    Thank you for the video bro! Could you tell is it possible to use url cache with combine (instead of fileManager or NSCsche? I tried but it appears to be impossible ( maybe I did something wrong or this feature is not available with combine at this moment.

    • @SwiftfulThinking
      @SwiftfulThinking  Před 3 lety

      Hi Stolenhen, you could do something like this? www.swiftbysundell.com/tips/constant-combine-publishers/

    • @stolenhen
      @stolenhen Před 3 lety

      @@SwiftfulThinking this is nscache isn’t it?

    • @SwiftfulThinking
      @SwiftfulThinking  Před 3 lety

      @@stolenhen Yea I think it's a good alternative solution though?

  • @manasvijaywargiya8218
    @manasvijaywargiya8218 Před 2 lety

    Hi Nick, Thanks for the wonderful course 😀.I've learned so much new things in this playlist.
    Is it possible to create an app to store online data json with images and close it and reopen the app with no internet access, will it get the data back stored in FileManager to the UI ?

  • @kasper3845
    @kasper3845 Před 2 lety

    Hi Nick! Did you figure out how to get rid of repeated viewModels. I mean if you open tree of objects you will see that there n repeated imageDownloadViewModels in your app

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

      Hi Kasper, Yes this is possible but I haven't covered it yet on this channel. Adding a class to download each image isn't that performance heavy. Obviously we can improve on it, but this is only an "intermediate" playlist haha

  • @thedrenkemp124
    @thedrenkemp124 Před 3 lety +1

    Hi love the video. Can u answer a question for me? How do I us textview(UITextView, shouldChangeTextin: NSRange , replacementText: String)
    I don’t know what to replace UiTextView, NsRange or string with. I want to added limited character to a textview. But I don’t know how to use the following code.

    • @SwiftfulThinking
      @SwiftfulThinking  Před 3 lety

      Hi Thedren, I'm not sure what that is. UITextView sounds like something from UIKit and not SwiftUI. I would recommend looking into TextField() and TextEditor() in SwiftUI! I covered them in the SwiftUI Bootcamp playlist.

  • @j1nMatt
    @j1nMatt Před 3 lety

    Hey Nick for some reason I had to init the photo cache inside the private init for PhotoModelCacheManager

  • @dugrut1325
    @dugrut1325 Před 2 lety

    Here is the error message:
    Error saving to file manager. Error Domain=NScocoaErrorDomain Code=4 "The file "8.png" doesn't exist. etc. 6, 7, 8, 9 etc

    • @mokanoir
      @mokanoir Před rokem

      You probably missed the exclamation mark (!) in line 23 (if-statement) in the file "PhotoModalFileManger.swift" :-)

  • @ThePhotodiver
    @ThePhotodiver Před 3 lety

    I am up to the point where we get our first data returned in the List view, and I am not getting any data. I added a print("Status code: \(response.statusCode)") in the handleOutput function and I get status code 200. I Then add a print("Success") in the case . finished: line in the URLSession for the downloadData() function and it returns a success. I Went to the DownloadingImagesBootcamp view and added this: Text("\(vm.dataArray.count)") which returns 0 for the dataArray. Not sure what is causing this not to work. I verified the URL for the data and it is correct. I went over all code and is the same.

    • @SwiftfulThinking
      @SwiftfulThinking  Před 3 lety

      Can you try printing the "returnedPhotoModels" in the PhotoModelDataService as well as the DownloadImagesViewModel. Is the data showing both times?

    • @ThePhotodiver
      @ThePhotodiver Před 3 lety

      @@SwiftfulThinking I tried that and in the debug window nothing shows up, but there are a lot up blank lines between the top of the output and the Success print.

    • @SwiftfulThinking
      @SwiftfulThinking  Před 3 lety

      @@ThePhotodiver Nothing is being printed for the "returnedPhotoModels"? Maybe you mistyped something in the PhotoModel and it's not decoding correctly? You must have missed something haha. I uploaded the project to my Github if you want to compare code: github.com/SwiftfulThinking

    • @ThePhotodiver
      @ThePhotodiver Před 3 lety

      @@SwiftfulThinking Thanks. I checked the PhotoModel and it is correct. I didn't see the DownloadingImage project in any of the files.

    • @SwiftfulThinking
      @SwiftfulThinking  Před 3 lety

      @@ThePhotodiver My mistake, try now!

  • @fre.helfer
    @fre.helfer Před rokem

    I love you

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

    Cache is pronounced like cash or cashay not catch. Great vid

  • @user-wm9lq4fd8i
    @user-wm9lq4fd8i Před 2 lety