How to Save an Image to a Local DB

Asked 2 years ago, Updated 2 years ago, 121 views

I'm trying to save the image in the app.
I am currently using Realm, but if it exceeds 16MB, it will crash and I am worried.
Should I change it to something else like CoreData or UserDefault?

I used this as a reference to save the image in Realm.
https://qiita.com/_ha1f/items/593ca4f9c97ae697fc75

swift realm

2022-09-30 20:21

1 Answers

Realm cannot store more than 16MB of properties.Specifications.

https://realm.io/jp/docs/swift/latest/ #section-53

UserDefaults doesn't have database functionality in the first place, so I don't know if they can meet the requirements, but UserDefaults loads everything into memory at startup, so if you save a lot of images, it compresses the memory and starts slowly.

CoreData is not limited by the size of the data, so I think it meets the requirements, but since binary data cannot be searched or sorted in the first place, there is little benefit in storing it in the database.
It is common to save the image as a separate file, and to store paths such as Realm and CoreData that indicate where to save it.


2022-09-30 20:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.