NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

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 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 October 1st.

Click to save your free spot now

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.