Saving images to the File Manager | SwiftUI Crypto App #9

  Рет қаралды 14,046

Swiftful Thinking

Swiftful Thinking

3 жыл бұрын

In the. last video, we successfully downloaded coin images into our list rows. They coin logos look great and give our app a much more professional feel. While most tutorials would probably stop here, we are going to take this an extra step further, and save these images to the .cachesDirectory within the FileManager. This will save the images to the device so that we can reuse images if they appear on the scree na second time, rather than downloading them again! Just another step toward making our app as efficient as possible.
It's important to note here that we are using the Caches Directory because these images aren't "required" in our app. If the directory ever gets too full, there's logic in the iPhone that will automatically start to empty the directory to free up space. Because of this, we are also including fall-back logic, so that if we ever don't have an image saved, we can easily start the download process for it.
*** LINKS:
- Downloadable Resources: www.swiftful-thinking.com/dow...
- CoinGecko API: www.coingecko.com/en/api
- CoinModel API: api.coingecko.com/api/v3/coin...
- Buy Me A Coffee: www.buymeacoffee.com/nicksarno
Next video: • Implement a custom and...
Last video: • Downloading Coin Image...
🤙 WELCOME BACK 🤙
WEBSITE: www.swiftful-thinking.com
DISCORD: / discord
GITHUB: github.com/SwiftfulThinking/
SAY THANKS: www.buymeacoffee.com/nicksarno

Пікірлер: 53
@AZMerf
@AZMerf 3 жыл бұрын
You never take the easy way out. You always promote good coding principles and techniques. Quality and efficiency reigns!
@SwiftfulThinking
@SwiftfulThinking 3 жыл бұрын
I'm trying 🥵 It's a personal pet peeve because when I started learning, I followed some courses that steered me in the wrong direction (and I had no idea at the time). Looking back it's very aggravating, especially since some of those courses are still top sellers on Udemy lol
@KimbrellBrad
@KimbrellBrad 3 жыл бұрын
@@SwiftfulThinking That trap of skimming over the details really does do a disservice to students! I am finding the same issues from courses that I thought were expertly done! Thanks for the detailed, lucid explanations Nick!
@dando2841
@dando2841 11 ай бұрын
Swift is the first programming language I have ever tried to learn. I've watched basically every video in your playlists (except advanced videos) in the past 2 months. I have to say- you are such a great teacher, and the fact that these videos are free is like winning the lottery. Thank you for your concise explanations, I feel like I've learned so many practical things from you. Stay awesome.
@SwiftfulThinking
@SwiftfulThinking 11 ай бұрын
That’s a lot of work on your part to get this far in only 2 months. Congrats and welcome to the channel! 🤙🥹🚀 thanks for the comment.
@KimbrellBrad
@KimbrellBrad 3 жыл бұрын
Wicked cool how the cache works! Another very portable concept for our toolkit! Thanks Nick!
@ShowMeLova
@ShowMeLova Ай бұрын
Thanks a lot Nick! Your contribute is impossible to overestimate. I am so grateful to you!
@harishalbat3762
@harishalbat3762 2 жыл бұрын
You're awesome man best teacher of Swift language I've ever seen. Keep going love your work!
@Julio-cu2hd
@Julio-cu2hd 2 жыл бұрын
These series are pure gold, has everything a developer needs. Thanks Nick
@SwiftfulThinking
@SwiftfulThinking 2 жыл бұрын
Thanks for watching Julio!
@mg_chai
@mg_chai 2 жыл бұрын
Very much appreciate your efforts and time. You learn all these in a hard way but inspire us to learn it the right way!!!
@SwiftfulThinking
@SwiftfulThinking 2 жыл бұрын
Thanks MG 🥳
@emremetilli727
@emremetilli727 2 ай бұрын
Your code quality is perfect! Thanks!
@paulraggett7837
@paulraggett7837 3 жыл бұрын
Loving this course! Thank you 👏👍
@morreke
@morreke 2 жыл бұрын
Brilliant ! Wish i already was at the same level as you, looks like second nature ! But, slowly getting there watching your videos ! Many concepts are starting to click now.
@mohd.rajeen4256
@mohd.rajeen4256 8 ай бұрын
Following this course from first video itself. Great learning experience. Although the UI till now looks simple and app only has 1 functional screen, but the main takeaway here are the efficient coding techniques and app architecture which you are following throughout this course. Will complete this hopefully.
@irfanrizvi161
@irfanrizvi161 3 жыл бұрын
I still got a lot to learn, thank you for everything bro.
@SwiftfulThinking
@SwiftfulThinking 3 жыл бұрын
How you doing bro? This is a tougher course I know.
@Nunny25
@Nunny25 2 жыл бұрын
Thanks as always :-)
@NathanWhite1
@NathanWhite1 2 жыл бұрын
Great video! Quick question - any reason to use a singleton for the localFileManager, but static methods for the NetworkingManager?
@daniilakmatov5693
@daniilakmatov5693 Жыл бұрын
It's grate course thanks bro!
@cinquain0
@cinquain0 3 жыл бұрын
good stuff
@mrglwatson
@mrglwatson 2 жыл бұрын
The get images code seems closely coupled to the coin model making it more difficult than it should to re-use , is this something that gets addressed in later episodes or perhaps in another project?
@williamwildsmith5162
@williamwildsmith5162 2 жыл бұрын
PDN. . . . = Pretty Darn Neat
@oronbz
@oronbz 2 жыл бұрын
Actually URLSession has it's own caching mechanism, so you pretty much get this out the box. If you turn on charles/proxyman, you'll see that no coin image is requested twice, even when you re-open the app. Although you did prove that the method has been called twice, but no request has been sent on consecutive method calls for the same image.
@oldschool84
@oldschool84 3 ай бұрын
Tell me what is situation if I want to develop e-commerce app with a lot of pictures? And big sizes of pictures. Is this also is a good practice for that purposes? Also, I want to use Core Data for that app?
@mustafadzhabrailov
@mustafadzhabrailov 8 ай бұрын
why data disappears from the file manager. when some time passes until you launch the application the images that were added to the file manager are downloaded from the Internet
@alexvaiman4966
@alexvaiman4966 6 ай бұрын
why reinvent the wheel, king fisher made for this.
@yasseraltamimi6171
@yasseraltamimi6171 2 жыл бұрын
Just a small tip. in 3:55 when you press enter to clean the screen, you actually can press the trash in the bottom right corner to clean the output console😄
@SwiftfulThinking
@SwiftfulThinking 2 жыл бұрын
ooo cool!
@gibber1sh-c6w
@gibber1sh-c6w 11 ай бұрын
@@SwiftfulThinkingCmd + K clear the terminal screen
@rtorcato
@rtorcato 2 жыл бұрын
If createFolderIfNeeded fails you are returning no error and executing the code after the call to the function. It would be better to use throws and that function and try it. Also if the image has been updated by the api there is no way for you to get the latest image changes.
@code_pilot
@code_pilot Жыл бұрын
Great Video! I have one question, why you didn't use NSCache, I used this class: class ImageCache { static let shared = ImageCache() private let cache = NSCache() private init() { } func set(for urlImage: String, image: UIImage?) { guard let image = image else { return } cache.setObject(image, forKey: NSString(string: urlImage)) } func get(for urlImage: String)-> UIImage? { cache.object(forKey: NSString(string: urlImage)) } }
@trevorschmidt8436
@trevorschmidt8436 Жыл бұрын
One thing that might cause an issue is that coins ids are based on their rank and they are being saved based on that. So if a coin were to change ranks, the cached image would still return the old coins image. What would be better is to store it with the image’s urlString.
@fre.helfer
@fre.helfer Жыл бұрын
For me the coin id is their name. That's what I'm receiving from coin gecko
@dglalperen
@dglalperen 2 жыл бұрын
Hey :) When i try to simulate the app it gives me following error: "the operation coudn´t be completed. (NSURLErrorDomain error -1)" Do you have any ideas why ? Because in when i google the error there is nothing about it Thank you !
@SwiftfulThinking
@SwiftfulThinking 2 жыл бұрын
Make sure you have the correct URL and are using HTTPS (not HTTP)
@dglalperen
@dglalperen 2 жыл бұрын
@@SwiftfulThinking thanks :)
@ppp-ti9yr
@ppp-ti9yr 2 жыл бұрын
I got some problems. It always shows "Error saving image. Error Domain=NSCocoaErrorDomain Code=4 "The file “omisego.png” doesn’t exist."" and can't save the data. I just donot know why.
@ppp-ti9yr
@ppp-ti9yr 2 жыл бұрын
i just solved the problem, i miss a ! in front of "FileManager.default.fileExists(atPath: url.path)". Thanks a lot, your video is really helperfull.
@ppp-ti9yr
@ppp-ti9yr 2 жыл бұрын
i just solved the problem, i miss a ! in front of "FileManager.default.fileExists(atPath: url.path)". Thanks a lot, your videos are really helperfull.
@Adventurevictoria
@Adventurevictoria 2 жыл бұрын
Nick !! amazing content like always. just oner thing to mention. saving a file in the source code will be performed in the main thread. which can cause a problem if the image is big or lots of downloading simultaneously. your screen will be laggy. so using a " DispatchQueue.global(qos: .userInitiated).async() { self.fileManager.saveImage(image: returnImage, imageName: self.imageName, folderName: self.folderName) }" it can be done in the background thread and screen wont be laggy no matter how big job . :D
@youssefmohamed1551
@youssefmohamed1551 4 ай бұрын
Why not using Core Data?
@SwiftfulThinking
@SwiftfulThinking 4 ай бұрын
CoreData is not good for images/videos/audios
@youssefmohamed1551
@youssefmohamed1551 4 ай бұрын
oh thanks@@SwiftfulThinking
@oricoh
@oricoh Жыл бұрын
Cache is pronounced Cash....
@SwiftfulThinking
@SwiftfulThinking Жыл бұрын
Cash money 🤑
@treydavis8269
@treydavis8269 2 жыл бұрын
Excellent video; "cache" is pronounced just like "cash", for future reference.
@SwiftfulThinking
@SwiftfulThinking 2 жыл бұрын
Thanks haha hopefully it wasn't too distracting for you
@chrisstromberg6527
@chrisstromberg6527 Жыл бұрын
Tomayto-Tomahto, to each his own Trey.
@treydavis8269
@treydavis8269 Жыл бұрын
To correct - Not to correct, I am myself, Chris.
@pepa007
@pepa007 Жыл бұрын
Very nice! Is there a repo with the LocalFileManager.swift file, please? I don't see it in Resources.
@jamshidbekhaydarov21
@jamshidbekhaydarov21 4 ай бұрын
Implement a custom and reusable search bar | SwiftUI Crypto App #10
18:21
Swiftful Thinking
Рет қаралды 17 М.
America will ban Chinese software and hardware in cars sold in U.S
9:04
The Electric Viking
Рет қаралды 14 М.
Secret Experiment Toothpaste Pt.4 😱 #shorts
00:35
Mr DegrEE
Рет қаралды 38 МЛН
Gym belt !! 😂😂  @kauermotta
00:10
Tibo InShape
Рет қаралды 18 МЛН
Каха заблудился в горах
00:57
К-Media
Рет қаралды 10 МЛН
Downloading & Caching Images in iOS with Swift
27:49
Sam Meech-Ward
Рет қаралды 11 М.
Add a custom Navigation Link for lazy loading | SwiftUI Crypto App #18
23:44
Why Agent Frameworks Will Fail (and what to use instead)
19:21
Dave Ebbelaar
Рет қаралды 35 М.
Save data and images to FileManager in Xcode | Continued Learning #26
50:39
Building our People UI in SwiftUI
19:50
tundsdev
Рет қаралды 1,9 М.
I built an image search engine
6:44
Beyond Fireship
Рет қаралды 288 М.
Play: The Secret Weapon for iOS Devs & Designers
10:12
Sean Allen
Рет қаралды 24 М.
Secret Experiment Toothpaste Pt.4 😱 #shorts
00:35
Mr DegrEE
Рет қаралды 38 МЛН