9. SwiftData Storing Images and Bug Fixes

Поделиться
HTML-код
  • Опубликовано: 13 окт 2024

Комментарии • 47

  • @stephanlorenz9898
    @stephanlorenz9898 7 дней назад

    Thank you for your lessions in that series. Your language and explanations are clear and understandable even for me as a non english native speaker. I‘m espacially thankfull for your report on bugs and the solutions that you present, not very often found in RUclips tutorials.

  • @joeliquori
    @joeliquori 9 дней назад

    This series was a wonderful teaching tool for how to get started with SwiftData. Unfortunately on iOS 18 there seem to be a couple of more bugs.
    -the first has to do with when typing into the synopsis panel and displaying the on device keyboard on a smaller phone like the iPhone 15, the view gets messed up and makes it so you are unable to see what you are typing while also messing with a few other things like the rating and the title.
    -the second is when deleting genres it no longer functions the way it did in the video. it deletes the genre from the genre list and for the book you were editing the genre list in, but it doesn’t delete them for any other book that is attached to them.
    -and then finally I sometimes get a bug when I add a genre that the color does not show up it just shows the name but there is no way to tell if you have toggled it on or off.
    I have been trying to solve these on my own but I have not come up with anything. in apple’s developer videos I can not find any changes that have been made that would cause these to happen. thanks again for the course it has been super helpful.

  • @andrejkling3886
    @andrejkling3886 9 месяцев назад +1

    Definitely amazing series 🎉 … thank you so very much for that ❤️ for your efforts and fantastic explanation 👌. Happy New Year 🥳 Stewart ! For You and Family 🎉🎉🎉 All the best!

  • @gakkieNL
    @gakkieNL 5 месяцев назад +1

    Great series. Think I'm gonna hold of from SwiftData for now and continue on the CoreData + MVVM path. Storing and syncing Images works great already. I wouldn't know where to put al my logic if I start using SwiftData. I like MVVM for that, don't know yet what best practise there would be with SwiftData (MV pattern?) . Perhaps we'll see a series from you on that in the future!

  • @gustavomonge1785
    @gustavomonge1785 9 месяцев назад +3

    Merry Christmas !!

  • @mario_luis_dev
    @mario_luis_dev 3 месяца назад

    this was a masterful series btw. Your work is very much appreciated Stewart ❤

  • @dibjr
    @dibjr 9 месяцев назад +1

    Thank you for another great video!

  • @RickyThompson-m9o
    @RickyThompson-m9o 9 месяцев назад

    Super series! I like your teaching style. thanks for all your efforts. I am new to swiftUI and was wondering if you had any videos on using TabViews and SwiftData, specifically how to pass info from one screen to another, such as, tracking a character Model showing a List of characters on one screen then moving to another tab to enter data for the character/Item selected on the first screen into another Model. Would appreciate being pointed in the correct direction.

    • @StewartLynch
      @StewartLynch  9 месяцев назад

      TabViews are not really meant for that Ricky. What you describe is either a NavigationStack or a modal sheet presentation. I have lots of videos on those topics. Send me an email (Links in my profile) if you want to discuss this further.

  • @jurgasbielinis2130
    @jurgasbielinis2130 8 месяцев назад

    Thank you Stewart for an interesting video. Also I wanted to ask if you or someone have come across such SwiftData/iCloud app issues: 1. In Settings > iCloud > Manage Account Storage: clicking on the app to delete its iCloud data - does not open the next page - it only shows a spinner and that's it. Maybe I missed something in the code or setup to enable it? 2. Images with some data keep disappearing after app is restarted, sometimes they re-appear after awhile (might be related to connection) - but I would expect it to cache locally instead of removing/re-adding them. Any ideas would be really appreciated. Thank you very much in advance!

  • @joshgoble
    @joshgoble 9 месяцев назад +1

    Great series! How would you go about resizing the image so that the data would take up less storage (other than jpg compression)? It seems like an area that you would never need the original full size image and having the image stored at a couple hundred kb rather than a few mb would be ideal?

    • @StewartLynch
      @StewartLynch  9 месяцев назад +2

      Here is a gist of two extensions that I include in most of my projects that allow me to scale images. gist.github.com/StewartLynch/683d19ed0cd9fb600607da0b6f99aa49

    • @joshgoble
      @joshgoble 9 месяцев назад

      @@StewartLynch thanks!

    • @joshgoble
      @joshgoble 9 месяцев назад

      I tried out your code and it’s a life saver. Right now I have the image data being stored in my documents directory, but I plan on switching over to storing it in swift data like you’ve shown here some I’m already using Swift data to store the url. Great video

  • @profgallaugher
    @profgallaugher 7 месяцев назад

    This was wonderful. I'm trying to store multiple images & am wondering how you'd handle a situation where you want the images to be stored externally (@Attribute(.externalStorage)) and also want deletions to cascade (@Relationship(deleteRule: .cascade)). Apparently putting both decorators above an array of data gives an error that they can't be composed. Thanks again for your work. It's great!

    • @StewartLynch
      @StewartLynch  7 месяцев назад +1

      Good question John. I have not explored that yet

    • @profgallaugher
      @profgallaugher 7 месяцев назад

      @@StewartLynch I'll have to explore this more. I'm finding that if I have a model with a single image, then save one image at a time to the model & query all saved values as an array of that model, I get the hidden .default_SUPPORT folder, BUT if I add a property to a SwiftData model that's an array of images and get this working, even with the .externalStorage - say something like this:
      @Attribute(.externalStorage) var imageArray: [Data?]
      if I look at the simulator's Application Support directory I don't see the hidden folder, so it's unclear if arrays of Data like this are even using .externalStorage. I may be completely missing something, but this is what I'm seeing right now. Will let you know if I discover more.

    • @StewartLynch
      @StewartLynch  7 месяцев назад

      I just realized that I am doing this in my new app. What I do is create a new model for the image with a single property that is data. then in my model I have an array of SitePhoto with a cascade delete. It all seems to work for me. Follow up with a DM on Mastodon or X if you want to discus more.
      @Model
      class SitePhoto {
      @Attribute(.externalStorage)
      var data: Data?
      var image: UIImage? {
      if let data {
      return UIImage(data: data)
      } else {
      return nil
      }
      }
      init(data: Data) {
      self.data = data
      }
      }

  • @gothefreakyway9509
    @gothefreakyway9509 9 месяцев назад

    Hey, nice video !
    I got a question - is it possible to pick an Image but with fixed aspect ratio with the Photospicker ?
    So lets say I am choosing an Image in my library, but then I get like a frame(fixed ratio like 2:1) on that Image where I can decide which part with that ratio I want to load.
    Or do i have to load it like so and make it resizable and scale it then ?

    • @StewartLynch
      @StewartLynch  9 месяцев назад +1

      I have not gone down that path myself. I do not think it is natively possible

    • @Grepsoft
      @Grepsoft 7 месяцев назад

      You cannot do it directly from the photopicker but you could load the image onto a canvas and then draw a rectangle on it for the frame and then use UIGraphicsImageRenderer to grab the area under the rectangle.

  • @mario_luis_dev
    @mario_luis_dev 3 месяца назад

    On an app I'm currently working on the `@Attribute(.externalStorage)` is not working as expected, as I see the whole blobs (50KB+) being stored internally (they show as BLOBs, not images, but still I think those are large files regardless). The .default_SUPPORT folder is also not storing the images created from this data; I see all the large blobs in the persisted table. Not sure what's going on. Do you think that SwiftData possibly only respects the `.externalStorage` if the Data you're trying to save is larger (like 1MB+)? I saw a blog from Paul Hudson that mentioned something along these lines, but there's no in-depth discussion about it, just a brief mention of this issue.

    • @StewartLynch
      @StewartLynch  3 месяца назад +1

      That may very well be the case. I think I read that somewhere too.

  • @gakkieNL
    @gakkieNL 5 месяцев назад

    Thanks! Keep up the great content!

  • @vmonzillo
    @vmonzillo 7 месяцев назад

    Thank you Stewart! I wonder if there is a way to pick photos from the camera just like that

    • @StewartLynch
      @StewartLynch  7 месяцев назад +1

      Funny you should say that. I am working on a video on that topic. Won’t be out for. month or so though.

    • @vmonzillo
      @vmonzillo 7 месяцев назад

      @@StewartLynch Wow! Great minds think alike 😅. I said that because I've just made a little project using something like that. Can't wait to see what you have for us!

  • @mario_luis_dev
    @mario_luis_dev 3 месяца назад

    another way to solve the Preview problem while leaving it in the Preview Contents folder is to add `#if DEBUG` directives on all previews

  • @jousufjacob8251
    @jousufjacob8251 8 месяцев назад

    Hi Stewart , thanks for you video , i have question here, if i want to fetch the image in the list of listview ,what should i do ?

    • @StewartLynch
      @StewartLynch  8 месяцев назад

      What do you mean by fetch the image? I don’t understand your question

  • @AndrewDChristie
    @AndrewDChristie 7 месяцев назад

    Thanks!

  • @RoxieS-pv4ke
    @RoxieS-pv4ke 9 месяцев назад

    in my project i can add and save Video files in SwiftData

    • @StewartLynch
      @StewartLynch  9 месяцев назад +1

      I don’t think you would want to save video files to a SQLLite database. I would just store the videos on device with an ID and then reference them in the database.

    • @joshgoble
      @joshgoble 9 месяцев назад

      @@StewartLynch Great point about not wanting to save the video in the database, but that does bring up an issue regarding CloudKit. If you were to store the videos locally in your apps .documentdirectory, what would be the way to have those files synced with CloudKit. I did a few searches and wasn't able to find any information on syncing a app folder.

    • @StewartLynch
      @StewartLynch  9 месяцев назад

      @joshgoble you would be better storing the video somewhere where it can be streamed and then just store the link

    • @joshgoble
      @joshgoble 9 месяцев назад

      @@StewartLynch thanks for the reply Stewart. I guess to make this less theoretical, I’m working on an app that specifically needs to be able to have offline video capabilities. It’s great that the swift data that holds all the urls and images can be directly stored in CloudKit, but if you absolutely need to have the videos stored locally in your apps documents directory, is there any way you know of to tell CloudKit to include an entire folder? I realize that syncing may take a few minutes, but I’m not sure hot to go about doing that? Or would you go to something else for that kind of syncing? Something like firebase?

    • @The1tjc
      @The1tjc 8 месяцев назад +1

      @@joshgoble Why not try saving the video file as shown for saving an image, as the video file is large it will be placed in external storage as Stuart shows. Then see if cloudKit can handle the sync. Maybe the CloudKit docs describe the limits on file sizes it can handle. Experimentation leads to knowledge.

  • @AndrewDChristie
    @AndrewDChristie 7 месяцев назад

    Thanks!