UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: How do you save/load your photos/images (Optimisation in terms of loading time in)

Forums > SwiftUI

@Bnerd  

First let me explain the concept: I am working on an app that a user can make some notes and keep also some photos in the notes. The data persists using CoreData and the images/photos are saved as .jpg in the Documents folder. Saving/Loading etc works as intented no issues.

The issue: When the user picks a note to view, if the note holds many photos i.e. 5-10 or more the note view will take a few seconds to load. The note view calls the photos in a ScrollView that holds a LazyVgrid.

I tried playing with the compression quality in my save func but the improvement is minimal.

My current solution: What works for me is to save the actual image/photo and save also a smaller thumbnail size image for list purposes. This way in the note view I could call only the smaller images and once tapped I could access the actual one.

Is this something that makes sense? Or there is a method or API I am missing.

Thank you for sharing how you approach similar cases.

2      

I am new to SwiftUI, but I think that your approach of showing Thumbnails makes sense. It lowers the amount of data transfered when the user doesn't want to see the picture in full size. Especially when you consider to load them through the network in the future.

Also you could maybe load the images/thumbnails asynchronously. That would let the user navigate to the "NoteView" and images will be displayed one after another, as soon as they are ready. Maybe you could even show placeholders until the corresponding image has been loaded.

The .task()-Modifier might come in handy for that :)

2      

Maybe you should store images in CoreData too (with option Allow External Storage). Or is it necessary use Documents folder?

2      

@Bnerd  

@Loahrs, thanks for the ideas, I had in mind the Async loading and a progressView until the image is available, although a small thumbnail that loads fast is more appealing to me at the moment..but duplicating the photos, I am not sure is an elegant solution..

@Sergey Do you mean save the images as Data? I know that CoreData is quite fast but do you believe it will make a difference loading the data and then transform to UIIMage and then Image? Unless I misunderstood your approach.

2      

Yes, save the images as Data. I had a project in which I saved and then displayed images from CoreData. Everything worked quickly.

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.