Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing Images in file system vs. Core Data

I am currently working on an iOS application that I allow the user to add images from their photo library into the application. I store these images on the devices file system, and access them when I need them (when they are in a UIScrollView, I could access them quite often)

I just wanted to get some opinions on this approach. Should I stay with the file system method, or would it be beneficial to store these I images in CoreData instead.

Any suggestions on this would be greatly appreciated.

Thanks.

like image 539
jabroni Avatar asked Mar 13 '11 19:03

jabroni


2 Answers

I don't think Core Data was really designed for storing this type of data. Doing so would be the moral equivalent of storing the image data into a SQL/relational database which isn't ideal either.

I have a similar situation where I have a bunch of images stored in hard targetted location (my image list never changes, so I just include them all in the application bundle) with a Core Data store that contains a lot of metadata about the images. All I keep in the Core Data of the image itself is the file name and then mash together the full file path during runtime when it is finally time to see the image. I don't have any problems with lag time or delays.

Even though I'm not showing the images in a UIScrollView, I still think you'd have little problem fetching the array of image information from the Core Data store and generating the full file path on the fly as cells are generated since those are just strings and the code for generating the UIImage is very compact. That or generate the same array of information, and then compiling an array of image paths before any cells are generating, like when the UIScrollView is just about to appear.

like image 134
Philip Regan Avatar answered Nov 12 '22 11:11

Philip Regan


You should use the file system method for anything bigger than a thumbnail.

For one thing, if you store in Core Data you have to store it has either data or a transformable attribute. In either case, you have an extra step to convert to image. If you store a file, you can just use the UIImage to load it straight in.

The main problem, however, is memory use, a faulted image will not be purged from memory like a UIImage will.

Update 2012-9-20: This answer is now obsolete. Core Data no has its own system for storing large chunks of data like images in external files.

like image 3
TechZen Avatar answered Nov 12 '22 10:11

TechZen