Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing UIImage in Core Data with the new External Storage flag

Tags:

I know that the storing of UIImage's in core data has been discussed a lot, such as here, but that was pre-ios5. Now that we have the external storage flag, do you guys think it would be a fine idea to store UIImage's directly in the entity, as a separate entity, or still on the disk?

Here is a source explaining the external storage option.

like image 491
Philippe Sabourin Avatar asked Oct 28 '11 03:10

Philippe Sabourin


1 Answers

Core Data Release Notes for iOS 5.0

When enabled, Core Data heuristically decides on a per-value basis if it should save the data directly in the database or store a URI to a separate file which it manages for you. You cannot query based on the contents of a binary data property if you use this option.

And from your link External Binary Data, the heuristic seems to be

Objects that are smaller than 1MB are stored in the database. For objects that are larger, an external file is created and the database just stores a reference to it.

So the following advice is still valid: CoreData : store images to DB or not?

  • < 100kb store in the same table as the relevant data
  • < 1mb store in a separate table attached via a relationship to avoid loading unnecessarily
  • 1mb store on disk and reference it inside of Core Data

The flag sets Core Data to follow that advice and automatically store images >1MB as a separate disk file.

like image 163
Jano Avatar answered Oct 20 '22 21:10

Jano