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

What is the best way to save an image using CoreData + CloudKit?

Forums > iOS

I'm developing an app to note clothes information with SwiftUI + CoreData + CloudKit. Users can add images of clothes as needed and save them together.

Currently, I am storing the images directly in CoreData as Binary Data type, and I am storing them with jpegData(compressionQuality: 0.3) compression, considering that users may store many images in the future.

However, this uses too much memory. When I save 20 items without images, it uses 80-150MB, and when I add app images, it takes up more than 300-400MB.(Is SectionedFetchRequest memory intensive??)

So I'd like to improve on this before releasing the app. I've found a way to save only the image URL, and store the actual image in a document file, but the problem with this is that if the user deletes the app, the image in the document file is also deleted. Should I implement it so that they are automatically saved to an iCloud document file?

If image data is being written continuously, what is the correct way to store images in coredata in the long run?



Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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

Reply to this topic…

You need to create an account or log in to reply.

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.