Storing UIImage in Core Data with the new External Storage flag

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.

Leave a Comment