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

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 พ.ย. 2024

ความคิดเห็น • 79

  • @patrickphilipot
    @patrickphilipot 3 ปีที่แล้ว +47

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

    • @SwiftfulThinking
      @SwiftfulThinking  3 ปีที่แล้ว +1

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

    • @tibettenballs4962
      @tibettenballs4962 2 ปีที่แล้ว +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 ปีที่แล้ว +7

    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!

  • @nevemra5
    @nevemra5 ปีที่แล้ว +1

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

  • @chrisstromberg6527
    @chrisstromberg6527 ปีที่แล้ว

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

  • @Josuegcp95
    @Josuegcp95 ปีที่แล้ว +2

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

  • @hygisonbrandao9251
    @hygisonbrandao9251 6 หลายเดือนก่อน

    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

  • @balabon
    @balabon 3 ปีที่แล้ว +4

    Awesome, better and better 👍

    • @SwiftfulThinking
      @SwiftfulThinking  3 ปีที่แล้ว

      Thank you as always Александр :)

  • @natgenesis5038
    @natgenesis5038 2 ปีที่แล้ว

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

  • @kenjyfukuda
    @kenjyfukuda 3 ปีที่แล้ว +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 10 หลายเดือนก่อน

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

  • @highRider72
    @highRider72 3 ปีที่แล้ว +2

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

    • @SwiftfulThinking
      @SwiftfulThinking  3 ปีที่แล้ว

      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 3 ปีที่แล้ว

      @@SwiftfulThinking got it, thank you!

  • @1slyboy
    @1slyboy ปีที่แล้ว

    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.

  • @andresraigoza2082
    @andresraigoza2082 2 ปีที่แล้ว

    You are like my Swift Manual. Thanks again

  • @bingl172
    @bingl172 2 ปีที่แล้ว +1

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

  • @OliverHeimann-z4q
    @OliverHeimann-z4q 2 หลายเดือนก่อน

    How would you load this steve-jobs image directly from your desktop instead of moving it to the assets folder? Let's assume your are on MacOS, how does this all work with absolute path names instead of these special application folders?

  • @Nunny25
    @Nunny25 3 ปีที่แล้ว

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

  • @readmoreapp
    @readmoreapp 2 ปีที่แล้ว

    Great explaination.
    Love from India

  • @maciusessa
    @maciusessa 2 ปีที่แล้ว +1

    great vid as always

  • @xcoo77
    @xcoo77 2 ปีที่แล้ว

    Great Video! Amazingly explained.

  • @philippegden9826
    @philippegden9826 2 ปีที่แล้ว

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

  • @uguraltnsy
    @uguraltnsy 2 ปีที่แล้ว

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

  • @akbar_logs
    @akbar_logs 11 หลายเดือนก่อน

    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  11 หลายเดือนก่อน

      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 3 ปีที่แล้ว +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  3 ปีที่แล้ว

      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!

  • @kavinda_dilshan_paramsoodi
    @kavinda_dilshan_paramsoodi 2 ปีที่แล้ว

    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.❤️

  • @mintuz
    @mintuz 3 ปีที่แล้ว +1

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

    • @SwiftfulThinking
      @SwiftfulThinking  3 ปีที่แล้ว

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

  • @carlosrivasrocks
    @carlosrivasrocks 3 ปีที่แล้ว +1

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

    • @SwiftfulThinking
      @SwiftfulThinking  3 ปีที่แล้ว

      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.

  • @joywu1
    @joywu1 2 ปีที่แล้ว

    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.

  • @andrefonseca4901
    @andrefonseca4901 2 ปีที่แล้ว +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  2 ปีที่แล้ว +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 2 ปีที่แล้ว

      @@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 2 ปีที่แล้ว

    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 2 ปีที่แล้ว

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

  • @Денис-ж3ф5р
    @Денис-ж3ф5р 3 ปีที่แล้ว +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  3 ปีที่แล้ว +2

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

    • @Денис-ж3ф5р
      @Денис-ж3ф5р 3 ปีที่แล้ว

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

    • @natgenesis5038
      @natgenesis5038 ปีที่แล้ว

      @@Денис-ж3ф5р relax SwiftUI is the best UI tool never seen even tho it still new .

  • @МахмуджанНиязов
    @МахмуджанНиязов 2 ปีที่แล้ว

    how using video files from file manager? please help me

  • @williamwildsmith5162
    @williamwildsmith5162 2 ปีที่แล้ว

    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?...?

  • @emdutt4012
    @emdutt4012 ปีที่แล้ว

    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 11 หลายเดือนก่อน

    simply genius

  • @erencelik964
    @erencelik964 3 ปีที่แล้ว +2

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

    • @SwiftfulThinking
      @SwiftfulThinking  3 ปีที่แล้ว

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

    • @erencelik964
      @erencelik964 3 ปีที่แล้ว

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

    • @erencelik964
      @erencelik964 3 ปีที่แล้ว

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

  • @frydaydeep6674
    @frydaydeep6674 2 ปีที่แล้ว

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

    • @frydaydeep6674
      @frydaydeep6674 2 ปีที่แล้ว

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

  • @dugrut1325
    @dugrut1325 2 ปีที่แล้ว

    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  2 ปีที่แล้ว

      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 2 ปีที่แล้ว

      @@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 2 ปีที่แล้ว

      @@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.

  • @avneetsingh2010
    @avneetsingh2010 3 ปีที่แล้ว +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  3 ปีที่แล้ว

      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

  • @ThePhotodiver
    @ThePhotodiver 3 ปีที่แล้ว

    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  3 ปีที่แล้ว

      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.

  • @fre.helfer
    @fre.helfer 2 ปีที่แล้ว

    👏👏👏👏👏 AMAZING

  • @Jump_Jay
    @Jump_Jay ปีที่แล้ว

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

  • @MrLawaghar
    @MrLawaghar 3 ปีที่แล้ว

    Great job.

    • @SwiftfulThinking
      @SwiftfulThinking  3 ปีที่แล้ว +1

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

  • @김이현시청용
    @김이현시청용 3 ปีที่แล้ว +1

    thx!!

  • @Lassund
    @Lassund 2 ปีที่แล้ว

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

  • @wandahu8058
    @wandahu8058 2 ปีที่แล้ว

    Good!

  • @zamnbro
    @zamnbro ปีที่แล้ว

    nahh

  • @holycrosscv
    @holycrosscv 2 ปีที่แล้ว +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 2 ปีที่แล้ว

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

  • @mig12394
    @mig12394 3 ปีที่แล้ว +1

    Awesome, better and better 👍