Storing UIImage in Core Data with the new External Storage flag

后端 未结 1 1144
囚心锁ツ
囚心锁ツ 2020-11-29 01:47

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 thi

相关标签:
1条回答
  • 2020-11-29 02:46

    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.

    0 讨论(0)
提交回复
热议问题