Save data and images to FileManager in Xcode | Continued Learning #26

Sdílet
Vložit
  • čas přidán 26. 08. 2024
  • In this video we switch gears and look at saving documents to the FileManager. This is a handy resource for any iOS developer where we can save documents (files, data, images, videos, etc.) directly to a user's device. As the developer, it becomes your responsibility to manage the data that you save to someone's device and therefore we need to know how to save data, fetch data, and also delete data!
    Learn more:
    iOS Storage Guidelines: developer.appl...
    File System Basics: developer.appl...
    Next video: • Save and cache images ...
    Last video: • Publishers and Subscri...
    🤙 WELCOME BACK 🤙
    WEBSITE: www.swiftful-t...
    DISCORD: / discord
    GITHUB: github.com/Swi...
    SAY THANKS: www.buymeacoff...

Komentáře • 78

  • @patrickphilipot
    @patrickphilipot Před 3 lety +41

    I'm amazed at how simple it looks when clearly explained. You have a real talent for teaching.

    • @SwiftfulThinking
      @SwiftfulThinking  Před 3 lety

      Thanks for the comment Patrick! I'm very happy to help.

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

      @@SwiftfulThinking he used to be a bully, and force me to eat dirt. now i eat bugs becuase its just a habit from him being a big ol meanie.

  • @Reallymellie
    @Reallymellie Před rokem +6

    Hey Nick, Just want to thank you for all the content you make and the hard work you put in this videos. I am really thankful for that! The way how you teach is just amazing!

  • @Josuegcp95
    @Josuegcp95 Před rokem +2

    You're a great teacher, thank you for the content.

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

    You should be the one writing Apples documentation. I feel their docs are the worst. And you are the best ate making it simple and clear! Thanks

  • @nevemra5
    @nevemra5 Před rokem +1

    Amazing as always. I love how detailed and slow you explain these complicated things. It really helps a lot.

  • @chrisstromberg6527
    @chrisstromberg6527 Před rokem

    I really appreciate the "best practices" approach you take in citing Apple guidelines. Another excellent video!

  • @balabon
    @balabon Před 3 lety +4

    Awesome, better and better 👍

  • @natgenesis5038
    @natgenesis5038 Před 2 lety

    You tought me SwiftUI from nothing to a pro thanks so much bro

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

    Many thanks for your explanation in an organized and easy-to-follow manner. I'm enjoying your series of video tutorials "SwiftUI Continued Learning."

  • @rivforest2395
    @rivforest2395 Před 6 měsíci

    simple, logical, easy to understand and follow. thank you for making this. How can you make the folder available to sync to the iCloud?

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

    Thank you! This is such a helpful tutorial. Super clear.

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

    great vid as always

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

    I noticed that the saved JPEG is much larger than the original JPEG. It would appear that the compressionQuality using 1.0 is not the same as the original quality. BTW - you can see the file saved by the simulator simply by opening the path on your Mac.

  • @user-yd9xy3rb4x
    @user-yd9xy3rb4x Před 2 lety +2

    I remember learning SwiftUI with you, which was fun, even though I was forced to learn UIKit. I am happy to understand that I still remember SwiftUI, so you did a great job, I guess.

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

      Haha! That's good to hear. SwiftUI > UIKit though 🥲

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

      @@SwiftfulThinking not always, UIKit words with maps better.

    • @natgenesis5038
      @natgenesis5038 Před rokem

      @@user-yd9xy3rb4x relax SwiftUI is the best UI tool never seen even tho it still new .

  • @akbar_logs
    @akbar_logs Před 8 měsíci

    simply genius

  • @andresraigoza2082
    @andresraigoza2082 Před 2 lety

    You are like my Swift Manual. Thanks again

  • @Nunny25
    @Nunny25 Před 2 lety

    Uff, long video, BUT very useful as always and FM is clear for me now. Thanks Nick.

  • @williamwildsmith5162
    @williamwildsmith5162 Před 2 lety

    Hi Nick,
    Some of the topics in this set of videos go over my head - firmly my fault (I'm a bit think sometimes, and getting on in years).
    Anyway, I think you have a talent for training people, and I think you have a winning formula with these individual videos.
    Great job Nick.
    How can I buy you coffee?...?

  • @kdtechniquesofficial6153

    Good work Nic. learned a lot. long video doesn't bother us at all because we wanna learn it properly. so itz okay. keep up the good work.❤️

  • @readmoreapp
    @readmoreapp Před rokem

    Great explaination.
    Love from India

  • @joywu1
    @joywu1 Před 2 lety

    I found the last step when add manager.deleteFolder() in VM's delete func then only can click save 1 time & many times in delete button, but when I click save again will show files not exit, when I study these code, I found should add manager.creatFolder() in VM's saveImage func, then will no longer show error message. if I delete the folder, it will create folder again when I click save button with no error.

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

    Great video! Quick question: Why are you using a singleton vs an environment object on app level for Local File Manager?

    • @SwiftfulThinking
      @SwiftfulThinking  Před 2 lety

      Hi Hans. Great question.... We use @EnvironmentObject to put an ObservedObject into the environment so that another View can access it. In this video, the LocalFileManager is not observed from the View. Instead, the ObservedObject is our ViewModel and then the ViewModel is referencing the LocalFileManager... The real question would be, why did we use a Singleton, in which case I used a Singleton here because this will be a global class that is used across the app. In a more advanced series I would use Dependency Injection instead.

    • @highRider72
      @highRider72 Před 2 lety

      @@SwiftfulThinking got it, thank you!

  • @xcoo77
    @xcoo77 Před 2 lety

    Great Video! Amazingly explained.

  • @emdutt4012
    @emdutt4012 Před rokem

    I am using Xcode 14.3 while saving the image after first click it shows the save successfully ,but then it's not showing any message.. if anyone here face same problem.

  • @akbar_logs
    @akbar_logs Před 8 měsíci

    I have a question?
    Question 1: What is the difference between saving Images Externally with the help of Core Data and saving images with the help of File Manager.
    Question 2: Images saved with the help of File Manager will sync with CloudKit?

    • @SwiftfulThinking
      @SwiftfulThinking  Před 8 měsíci

      1. CoreData doesn’t support image formats and is usually not used for saving Images / Videos / etc. Apps with CoreData will often save “imageUrlString” to CoreData and then load image from FileManager (or elsewhere).
      2. FileManager does not sync across devices. I’m not sure if there’s a CloudKit sync option.
      3. Most apps will use an Image SDK rather than manually doing it. I wanted to teach an example here, which is important to know and understand, but I would recommend an SDK such as Kingfisher or SDWebImage to load and save the images. In which case, you won’t be dealing w FileManager or CloudKit anyway🤙

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

    For example, the Home app allows the user to save an image as a background. I would assume this would be using this concept. Also, can I find the image I saved in the simulator in the folder hierarchy?

    • @SwiftfulThinking
      @SwiftfulThinking  Před 3 lety

      Yea, you should be able to find the file. If you print out the path where we save the image you'll see the exact location. I think it will be pretty deep into the hierarchy though!

  • @ThePhotodiver
    @ThePhotodiver Před 3 lety

    I really enjoyed this video. I am working on an App that uses a JSON file, and would like to create a desktop app that would allow me to create the data for that JSON file that will be used in the first app. This will help me for sure in getting to that point.

    • @SwiftfulThinking
      @SwiftfulThinking  Před 3 lety

      Hi ThePhotodiver! I'm glad the video helped. The code should be very similar except instead of using an Image you just save your JSON data! Thanks for watching.

  • @uguraltnsy
    @uguraltnsy Před 2 lety

    What should I do for it to appear in the gallery?

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

    How would you use this to sync files across devices similar to how Photos app works

    • @SwiftfulThinking
      @SwiftfulThinking  Před 2 lety

      This tutorial for the FileManager is specific to the device. If you want to share across devices, you can integrate CloudKit!

  • @wandahu8058
    @wandahu8058 Před rokem

    May I ask why you deleted the image from the file manager, and then the view did not update immediately but still shows the image.

    • @wandahu8058
      @wandahu8058 Před rokem

      Interestingly, when the get image function is added, the view is still not updated

  • @philippegden9826
    @philippegden9826 Před 2 lety

    Nick, When would you need to use NSFilePresenter / NSFileCoordinator? Phil

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

    Is it possible to sync the data in FileManager across devices with iCloud? How? Thanks!

    • @SwiftfulThinking
      @SwiftfulThinking  Před 2 lety

      Hi Carlos! Well the FileManager is specific to the current device, however, we can use CloudKit to sync across the user's iCloud. That's a whole different framework though.

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

    Congratulations, it was a really nice content. do you intend to share the code

    • @SwiftfulThinking
      @SwiftfulThinking  Před 3 lety

      Thanks for watching Eren! Yes, the full source code is available on my Github: github.com/swiftfulthinking

    • @erencelik964
      @erencelik964 Před 3 lety

      @@SwiftfulThinking Thank you for your answer, I hope your content will continue, you are doing very well.

    • @erencelik964
      @erencelik964 Před 3 lety

      @@SwiftfulThinking Although I know most of the topics you are telling, I'm still watching: D

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

    how using video files from file manager? please help me

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

    Guys I have written the data into a file in documents directory using Swift's standard File manager functions... I am able to view through xcode terminal but while testing in real iOS I don't see any file... Can anyone let me know if it is even possible to view the file???

    • @SwiftfulThinking
      @SwiftfulThinking  Před 3 lety

      You can do this if you save it on a simulator on your computer. You're probably better off printing out the path from Xcode and then trying to find it. It's a challenge to get to because it's very deep, but I think this may help: stackoverflow.com/questions/25198840/document-directory-path-of-xcode-device-simulator

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

    thx!!

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

    Hi Nick, thanks for all your awesome videos! Just one question: in this video the func getImage retrieves and returns an UIImage. But how can i retrieve and return an mp3 file? What data type should I use in the return?

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

      For audio and video, you can write the Data to a URL and then return the URL back to the application. We use AVPlayer to play these files, which can be initialized with a URL. You also can use the remote URL if u don’t want to write to the FileManager, but I often do anyway 👍

    • @andrefonseca4901
      @andrefonseca4901 Před 2 lety

      @@SwiftfulThinking Thanks a lot Nick, it worked! The reason I couldn’t play the remote URL directly is that I developed my whole player interface (buttons, slider, playing time, etc) using AVAudioPlayer (based on your video Continued Learning #9). But later I found out AVAudioPlayer does not play remote files; only AVPlayer plays remote URLs. So I decided to download the mp3 files in order to use my interface, which is working now. (By the way, it would be nice if you could post a video showing how to make an audio player with slider, controls, etc, using AVPlayer - I tried but was not able to do it).

  • @wandahu8058
    @wandahu8058 Před rokem

    Good!

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

    👏👏👏👏👏 AMAZING

  • @MrLawaghar
    @MrLawaghar Před 3 lety

    Great job.

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

      Hey Muhammad.. welcome to the channel! Thanks for watching.

  • @dugrut1325
    @dugrut1325 Před 2 lety

    Great video, but how can the user see any files created in Files.app, I notice files I create the are not available to the user, even though I can see them thru terminal. Is there a setting to set in Xcode when the app is compiled, to allow these files accessible to the user/device?

    • @SwiftfulThinking
      @SwiftfulThinking  Před 2 lety

      The Assets folder is part of the application bundle. It is included in your app when you ship it to the App Store. Therefore, you can read from it but cannot write to it. If you need to write, you should write to a local URL on the device using the FileManager!

    • @dugrut1325
      @dugrut1325 Před 2 lety

      @@SwiftfulThinking thanks for the reply. I watched the bootcamp series for the second time also going through the Continued Learning series a couple times and now finally it's getting through to this old timer. I seem to understand the howto for path/folders/files. This video exercise I tagged all the functions and them folded them up, It made it short and concise and I finally visualized it. It was a great video. I noticed once you delete the folder you could no longer save the image, so I added the func createFolderIfNeeded() before, to check if the folder was still available. Works

    • @dugrut1325
      @dugrut1325 Před 2 lety

      @@SwiftfulThinking Thanks for replying. It is, not exactly my question. But I found out the answer. I was asking about writing files through FileManager. I wanted the user to see these files that the app creates. I found through another Swift Tuber to set the 'file sharing' options in Info. Everything with that problem is resolved.

  • @frydaydeep6674
    @frydaydeep6674 Před 2 lety

    37:40: vm = Localmanager.instance() poped up, code changed and I didn't see you covered it? Captain Nick

    • @frydaydeep6674
      @frydaydeep6674 Před 2 lety

      what a clown i am : I used state var instead of @StateObject and infoMessage just won't show and no bug report from compiler

  • @Jump_Jay
    @Jump_Jay Před rokem

    Whew this was a long video, but i took small bites out of it until completed. 😁

  • @Lassund
    @Lassund Před rokem

    NO I love a detailed video, let it be long if it is.

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

    its kinda funny NICK. how you used to kick me!
    not nice dude. we were young, and you used to KICK ME!
    not KOOL dude. not KOOL at all.

  • @zamnbro
    @zamnbro Před rokem

    nahh

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

    This is a really helpful series! Thanks so much!
    To get rid of the pesky constraint errors in the output, just add the following to the to the @main first view:
    .onAppear {
    UserDefaults.standard.setValue(false, forKey: "_UIConstraintBasedLayoutLogUnsatisfiable")
    }

  • @SigmaPC94
    @SigmaPC94 Před 2 lety

    You are the best can I have your insta handle please 😍😍

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

    Awesome, better and better 👍