我知道 UIImage 在核心数据中的存储已经讨论了很多,例如 这里,但那是 ios5 之前的版本.现在我们有了外部存储标志,你们认为将 UIImage 直接存储在实体中、作为单独的实体还是仍然在磁盘上是一个好主意?
这里是解释外部存储选项的来源.
iOS 5.0 核心数据发布说明
<块引用>启用后,Core Data 会启发式地根据每个值决定是否它应该将数据直接保存在数据库中或将 URI 存储到它为您管理的单独文件.您不能根据如果使用此选项,则为二进制数据属性的内容.
从您的链接 外部二进制数据,启发式似乎是
<块引用>小于 1MB 的对象存储在数据库中.为了更大的对象,创建一个外部文件和数据库只是存储对它的引用.
所以以下建议仍然有效:CoreData : store是否将图像转入数据库?
<块引用>1mb 存储在磁盘上并在 Core Data 中引用它
该标志设置 Core Data 遵循该建议并自动将 >1MB 的图像存储为单独的磁盘文件.
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.
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.
这篇关于使用新的外部存储标志将 UIImage 存储在核心数据中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!