Download and save images using FileManager and NSCache | Continued Learning #28
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...
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.
Thanks Amith! 😃 More videos coming soon!
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
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.
Thank you so much for this Nick! You are helping out the community to an extent you cannot even imagine! ❤
I can't describe how much did I learn from this playlist. Thank you Nick!
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.
Whew! Great course Nick! Looking forward to diving into the next lessons!
Thank you, Nick, so much. Cannot show how much I do appreciate your help.
Your fan from Uzbekistan!
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. :)
Haha happy to help! Thanks for watching Manish
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.❤️😘
Hey nick what a piece of art thanks for teaching me all this valuable stuff, you are badass. God bless you
Thanks man glad it helps
Best wholistic SwiftUI tutorial
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. 👍👍👍
Thanks! I’m very happy to hear this 👍
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 :-)
Great of knowledge you’re blessing us with! Thank you.
Hi Yoko! Thanks again :)
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!
Thanks for watching Ole! I've seen you comment on a few videos now and it seems like you're progressing 😄
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.
Ahhh good catch. Yea sometimes printing to debug is the best route!
Amazing stuff. Thanks so much Nick. I love your teaching style and can't wait for your next series of videos!
Thanks Scott! I'm almost done with the next playlist :)
@@SwiftfulThinking awesome, can't wait!
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.
Hi Keval! Haha I'm glad you like them. More videos coming soon don't worry 🤓
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..
thanks you ❤..you are hardworking and you are a good teacher...❤
Excellent video Nick! Thanks a lot!
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. 🙂
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
Thank you Nick! This course was very helpful.
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!
Yasser!! I'm just glad you are enjoying the vids 😎
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!
YOU ARE AWESOME! THANK YOU SO MUCH!!!
Keep them coming Nick, did you go into a slumber LOLLLL
😂 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 😩
I learnt, loved it, a great teacher!
great tutorial - thank you!
if you know about async image you can use async image to download those images in a convenient way.
Thank you for your videos!
When will you publish new one?
Can't wait)
Haha thanks for watching mkpwnz! I just finished editing my next course and will post it this week :) 25+ videos 🥳
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
I couldn’t hear any background noise, I’m guessing it was noise in your background!
@@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...
Thanks for your content. Keep it going!
Thank you Nick 🤩
Thanks Tech Rag!!
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.
very impressive demonstration !
Thanks again Michel!
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!
6 to go!
5 watches done, and moving on now. Great video!
Excellent tutorial!!!
Thank you! Cheers!
Thank you! 😍😍😍
You're welcome 😊
This is great!!! Thank you so much
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.
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.
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?????
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.
Hi, Nick! The video is great! Could you explain why you decided to use FileManager? Caching works with a single "var cache" property.
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
@@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 👌
Good!
Hi Nick, your tutorial is awesome. Please consider extending your app to store the downloaded JSON objects in Core Data?
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/
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?
What error are u getting?
@@SwiftfulThinking Arggghhh. cut and pasta failure:::
@@SwiftfulThinking The data couldn't be read because it is missing.
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.
Hi Stolenhen, you could do something like this? www.swiftbysundell.com/tips/constant-combine-publishers/
@@SwiftfulThinking this is nscache isn’t it?
@@stolenhen Yea I think it's a good alternative solution though?
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 ?
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
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
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.
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.
Hey Nick for some reason I had to init the photo cache inside the private init for PhotoModelCacheManager
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
You probably missed the exclamation mark (!) in line 23 (if-statement) in the file "PhotoModalFileManger.swift" :-)
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.
Can you try printing the "returnedPhotoModels" in the PhotoModelDataService as well as the DownloadImagesViewModel. Is the data showing both times?
@@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.
@@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
@@SwiftfulThinking Thanks. I checked the PhotoModel and it is correct. I didn't see the DownloadingImage project in any of the files.
@@ThePhotodiver My mistake, try now!
I love you
Cache is pronounced like cash or cashay not catch. Great vid
just let him, he earned it 10 times more